flutterxcodexcode-scheme

Flutter flavor build from Xcode different main.dart


I want to build my app in different flavors. For Android everything works fine. For iOS only when i use vscode or the flutter build command line to build my app. When I try to build and run my app from xcode, it always uses the main_x.dart file I last used in vscode as the entry point. Xcode always uses the correct app identifier, icons, etc. (everything from xcode). So my scheme setup seems to work, but xcode seems to ignore my lauch.json and just run the last used main_x.dart.

Lets say my flavors are choco and vanilla. In the project runner info I have: Debug-choco, Debug-vanilla, Release-choco, Release-vanilla, Profile-choco, Profile-vanilla. On Edit Schema choco is Execute -> Debug-choco, Test -> Debug-choco etc. On Edit Scheme vanilla is Run -> Debug-vanilla, Test -> Debug-vanilla etc.

So when I hit run on vanilla schema, I expect to run my main_vanilla.dart. When i hit run on choco schema i expect to run my main_choco.dart. But if my last build in vscode was choco, then in xcode it will always run main_choco.dart no matter which scheme i select there.


Solution

  • After many hours of research I finally found the solution. In the build settings there is a custom setting called "FLUTTER_TARGET" where you have to set the paths to your main.dart files. ALL tutorials and guides completely ignore this. https://youtu.be/4Y7WaeU3P60?si=_FF6LNeJGDQjQWbR&t=852 In this guide you can see at the linked time at the bottom of the screen what I mean.