I followed this tutorial to add flavors to my Flutter project.
If I build the app with a specific flavor from command line, works perfectly. This is an example:
fvm flutter run -t lib/main_prod.dart --release --flavor=prod
In the Flutter project I've created three entry points:
main_dev.dart
void main() async {
AppConfig devAppConfig =
AppConfig(appName: 'My App', flavor: 'dev');
Widget app = await initializeApp(devAppConfig);
runApp(app);
}
main_stage.dart
void main() async {
AppConfig stageAppConfig =
AppConfig(appName: 'My App', flavor: 'stage');
Widget app = await initializeApp(stageAppConfig);
runApp(app);
}
main_prod.dart
void main() async {
AppConfig prodAppConfig =
AppConfig(appName: 'My App', flavor: 'prod');
Widget app = await initializeApp(prodAppConfig);
runApp(app);
}
And the initializeApp() method:
Future<Widget> initializeApp(AppConfig appConfig) async {
WidgetsFlutterBinding.ensureInitialized();
...
//save app flavor on sharedPreferences
resources.prefs.setFlavor(appConfig.flavor);
...
return MyApp(appConfig: appConfig);
}
At this point, when I archive the iOS project (Product -> archive), by default appConfig.flavor got 'dev' value.
The product bundle identifier that I set on xCode Build Settings (TARGETS -> Runner -> Build Settings -> Product Bundle Identifier) are:
For DEBUG
For RELEASE
I'll share futher project info if it's needed.
Make sure you are referencing those main dart files i.e. main_dev.dart, main_prod.dart, and main_stage.dart on Xcode. You can do it from TARGETS -> Runner -> Build Settings and then search FLUTTER_TARGET.
There you need to give a path for different environments as in the image below:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With