How to Solve Target file “lib/main.dart” not found In Flutter ?

· 3 min read
How to Solve Target file “lib/main.dart” not found In Flutter
How to Solve Target file “lib/main.dart” not found In Flutter

Sometimes when users run a project he may error that state about Target File “lib/main.dart” not found so in this article we will go through How to Solve Target file “lib/main.dart” not found In Flutter?

How to Solve Target file “lib/main.dart” not found In Flutter?

So basically when you execute this

flutter run

Flutter tries to find the main. dart in /lib directory.

You can run any file from any DIR provided that you set the target file path, for example.

flutter run -t lib/main_dev.dart

or

flutter run lib/dev/main_dev.dart

An alternative to flutter run -t lib/main_dev.dart in VS Code with the debugger tool.

  • Click “Add Configuration” and add the following or add manually:
  • .vscode/launch.json
    "configurations": [
    
       {
         "name": "Flutter",
         "request": "launch",
         "type": "dart",
         // "args": ["--enable-software-rendering"]
         // "flutterMode": "profile", //debug //release 
         "program": "${workspaceFolder}/lib/main_dev.dart"
       }
     ]

    VSCode Users:

  • Check folder .vscode>launch.json and add configuration:
    if you have it already changes a “program”: “path of main.dart example: lib/main.dart”

     {
        "name": "Dart",
        "type": "dart",
        "request": "launch",
        "program": "lib/main.dart"
    },
  • In Android Studio
  • Left Click in main.dart
  • Right, Click in profile main.dart this executes a snapshot application to configure the root profile a run your app.
    Android Studio Flutter Agency
    Android Studio Flutter Agency

    If you are using VSCode user gives a try the below method.

  • Delete the .vscode folder in your project directory and rerun the program.

Conclusion :

Hope you like our articles.

You can drop us Feedback/Suggestions for the same.

In this article, We have been through How to Solve Target file “lib/main.dart” not found In Flutter?

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply