Flutter : Target file "lib/main.dart" not found
You can run any file from any DIR provided that you set the target file path, example:
flutter run -t lib/main_dev.dart
OR
flutter run lib/dev/main_dev.dart
UPDATE (2020 February 5th)
It is however not advisable to remove main.dart from your project.
I'm sure most of you found this link because you are setting up / configuring your app to accommodate for different environments e.g. dev, stg, beta and prod.
Example:
main_dev.dart:
void main() async {
dynamic configuredApp = AppConfig(
appName: 'Flutter',
flavorName: 'development',
appVersion: 1.0,
apiBaseUrl: 'https://dev-api.example.com/'
);
runApp(App(configuredApp));
}
main.dart
class App extends StatefulWidget {
final dynamic configuredApp;
App(this.configuredApp);
@override
_AppState createState() => _AppState();
}
As it turns out some build steps will fail in Android Studio mostly Gradle related if you don't have a main.dart file and method main() {} referenced inside this file.
- Common build errors (AndroidX migrate, APK build etc.)
More info / solutions below related to flutter build error: finished with non-zero exit value 1
- issuecomment
- issuecomment
- issuecomment
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"
}
]
Hope this helps.
Flutter is looking for main.dart
in lib
folder while you must have had file inside any other package.
Best solution is to place your main.dart
file just inside lib
folder. Flutter run command will work then for sure.
It worked for me.
main.dart
url should be:
<app dir>/lib/main.dart