Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flavoring Flutter iOS: by default with dev configuration

Tags:

xcode

ios

flutter

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

  • Debug-dev -> com.myapp.dev
  • Debug-stage -> com.myapp.stage
  • Debug-prod -> com.myapp

For RELEASE

  • Release-dev -> com.myapp.dev
  • Release-stage -> com.myapp.stage
  • Release-prod -> com.myapp

I'll share futher project info if it's needed.

like image 445
Sami Issa Avatar asked Nov 21 '25 16:11

Sami Issa


1 Answers

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:

enter image description here

like image 131
Pratik Avatar answered Nov 24 '25 06:11

Pratik



Donate For Us

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