Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flavors in Flutter

Flavors in Flutter

Mahtab Tadayon

November 07, 2020
Tweet

More Decks by Mahtab Tadayon

Other Decks in Programming

Transcript

  1. Mahtab Tadayon § Software Engineer at MediamarktSaturn Retail Group §

    Founder of Flutter Explained § YouTube content creator PAGE 2
  2. Agenda Enviornment & Flavor Flavors in Action Configure Flutter Project

    Setup Flavors for Android PAGE 3 Optimize workflow with Android Studio & VSCode
  3. Environment § A computer system, in which a software will

    be deployed § Personal projects § developer's workstation § Industrial projects with end users § Development environment § Testing environment § Production environment PAGE 4
  4. Flavor § One source code for multiple projects § Each

    flavor is a product for itself § Each flavor has different environments § Set different URL for api calls, icons and names § The concept of flavors is from Android apps § Flavors are also possible for iOS apps PAGE 5
  5. Environment vs. Flavor Environment § One and same application §

    Mainly for deployment § The behavior and the visualization don’t change Flavor § One source code with multiple apps § Use different app's name, icons and package name § Each flavor can be an own product PAGE 6
  6. Workflow PAGE 11 void main() { mainCommon(config); } void main()

    { mainCommon(config); } void mainCommon(AppConfig config) { runApp(MyApp(config)); } main_cactus.dart main_leaf.dart main_common.dart class AppConfig {} App_config.dart
  7. Configuration Steps § Rename main.dart --> main_common.dart § Create an

    AppConfig class to store the configuration, such as flavor name, API endpoint … § Create main.dart file for each flavor § main_cactus.dart § main_leaf.dart § Adjust the main_common.dart with appConfig parameter PAGE 12
  8. Setup Flavors for Android § Adjust the build.gradle § FlavorDimensions

    are the same for all flavors § Different app ids for different flavors § Add app icons for each flavor § Run Flutter § flutter run -t lib/main_dev.cactus --flavor cactus § flutter run -t lib/main_leaf.dart --flavor leaf PAGE 16
  9. Build command § Run Flutter build with flavor § flutter

    run -t lib/main_cactus.dart --flavor cactus § flutter run -t lib/main_leaf.dart –flavor leaf PAGE 19
  10. Conclusion § Flavor help us to: § Have multiple projects

    from a single code base § Reduce amount of code and time § Use them for different development stages § Customize each project PAGE 23