flutter build ios ignores --target

Viewed 164

I am having an issue of building ios application with flutter.

I run the following command

flutter build ios --flavor development --debug --target=lib/main_development.dart

But the error shows

Error: Error when reading 'lib/main.dart': No such file or directory
package:my_app/main.dart: Error: No 'main' method found.
Try adding a method named 'main' to your program.

There is no main.dart in my application. Not sure if anyone know where in ios can override this value?

Thank you

==========================================================

Update 1:

My main() function in lib/main_development.dart looks like

Future<void> main() async {
  await DotEnv.load(fileName: "development.env");
  await _configureAmplify();

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => CognitoServiceChangeNotifier()),
        ChangeNotifierProvider(create: (_) => UserProfileChangeNotifier()),
        ChangeNotifierProvider(create: (_) => BottomNavigationBarCurrentIndexChangeNotifier()),
      ],
      child: MyApp(),
    ),
  );
}
1 Answers

The error isn't saying that you don't have a main.dart file but rather don't have a main() {} method. Dart needs a main() {} method to run your program.

You don't need to change the name of the file so long as it has a method named main in which you run your code. It should contain the Flutter runApp().

E.g.

void main() {
  runApp(const MyApp());
}
Related