When running flutter run -t lib/main.dart it results in FLUTTER_TARGET=/Users/sven/development/flutter_flavor_demo/lib/main.dart. running flutter run -t lib/main_dev.dart results in FLUTTER_TARGET=/Users/sven/development/flutter_flavor_demo/lib/main_dev.dart. Generated.xcconfig is generated by flutter and contains information like the FLUTTER_BUILD_NUMBER or the FLUTTER_TARGET which we defined by running flutter run with the -t flag. There should be already three configurations. Open the ios module in XCode ( open ios/Runner.xcworkspace) and take a look at the contents of the Runner/Flutter folder. Build configurations define properties which we can reference later. We start by looking at build configurations in XCode. Set up schemes in iOS Project Build configurations In the next step we will configure our ios project so it can create two different apps each with its own package name and app name. That means we couldn't install the dev and prod flavor side by side on our device because both share the same package name which must be unique. You may have noticed that the displayed package name (bundle identifier in ios terms) stays the same. We can create and run different flutter flavors in our app. In this case flutter run without t flag wont work anymore and you have to use the flag for both prod and dev. Note: You could also rename the main.dart file to main_prod.dart. flutter run -t main_dev.dart for the dev flavor.ĭepending on which entrypoint you choose you should see the corrosponding flavor screen on your simulator or device.Or just flutter run because it uses main.dart as default. flutter run -t main.dart for the prod flavor.We can run those different entrypoints with the -t flag (t for target) of the flutter command: Also the main widget FlavorDemoApp takes a Flavor as input, so it can decide in its build method what background color to choose and what text to display depending on the given flavor. A Flavor enum is defined, which we use to distinguish between flavors. In regards to flavors only the first lines of the file are interesting. The widget, which you see in the screenshot above, is defined in flavor_demo_app.dart. You can find the source code for the whole app here. It can be build in two flavors devand prod and will display its current flavor and the app's package name in the middle of the screen. Therefore follows my step-for-step guide for configuring flavors in flutter for iOS. For android those tutorials worked great but for iOS in everyone of them a litte piece of information was missing and I had to play arround quite some time before I got it right. But how can this be achieved within flutter? There are a few blog posts online showing how to do it. In Android those versions are called flavors and in iOS this can be done with schemes. A development version which uses the development backend, a staging version which uses the staging backend and, you guessed right, a production version which uses the production servers. In my latest flutter project I needed to create different versions of my app for the different development environments.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |