Skip to content

enzodanjour/flutter_flavours

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Flavours

development enviroments

A demo using Flutter flavorizr to create multiples flavors(enviroments) in this case, i create four envs being them: Quality Assurance(Qa), Development(Dev), Homologation(Hom) and Production(Prod)

Steps to config

  1. add package flutter_flavorizr: ^2.0.0 in dev_enviroment
  2. add settings of enviroments in pubspec.yaml in my case is:
flavorizr:
  app:
    android:
      flavorDimensions:  "flavor-type"
    ios: null
  flavors:
    dev:
      app:
        name: "Flutter Flavor Dev"

      android:
        #bundle identifier
        applicationId: "br.com.flutter.flavor.dev"

      ios:
        bundleId: "br.com.flutter.flavor.dev"
    hom:
      app:
        name: "Flutter Flavor Hom"

      android:
        applicationId: "br.com.flutter.flavor.hom"

      ios:
        bundleId: "br.com.flutter.flavor.hom"
    qa:
      app:
        name: "Flutter Flavor qa"

      android:
        applicationId: "br.com.flutter.flavor.qa"

      ios:
        bundleId: "br.com.flutter.flavor.hom"
    prod:
      app:
        name: "Flutter Flavor"

      android:
        applicationId: "br.com.flutter.flavor"

      ios:
        bundleId: "br.com.flutter.flavor"
  1. generate code automatically with flutter pub run flutter_flavorizr -p android:androidManifest,android:buildGradle,flutter:flavors,flutter:app,flutter:pages,flutter:targets in this case i pass the params because i dont need to setting on ios. if you have ios run only flutter pub run flutter_flavorizr. This step add all config in android/app/build.gradle and ios directories to run the flavours

  2. If you need you can change icons in diferents flavors, to do that just simply add in android/app/src/ add res with resources of your app, with diferents logos.

  3. if you need, you can add diferents firebases enviroments, to do that just simply add google-services.json(Android) on android/app/src/ and when run has another enviroment. P.S.: Your CI can remove the unecessary enviroments to all devs has resources, with for example production keys of firebase

  4. in flavours.dart you can config to create base url to connect with api simply seeing the enviroment.

Steps to run the env

Run command above: flutter run --flavor <Your env Name> -t lib/main_<Your class of env name>.dart in my case to run dev enviroment i do: flutter run --flavor dev -t lib/main_dev.dart

And now your enviroments is separeted. if you have running on vscode, you can easyly add this setting in your project to run on debug diferents enviroments

  {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Development",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_dev.dart",
                "--flavor",
                "dev"
            ]
        },
        {
            "name": "Quality",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_qa.dart",
                "--flavor",
                "qa"
            ]
        },
        {
            "name": "Homologation",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_hom.dart",
                "--flavor",
                "hom"
            ]
        },
        {
            "name": "Production",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_prod.dart",
                "--flavor",
                "prod"
            ],
        },
    ]
}

Steps to build flavours

Run with command: flutter build <your target> --flavor <Your env Name> -t lib/main_<Your class of env name>.dart in my case to build appbundle prod enviroment i do: flutter build appbundle --flavor prod -t lib/main_prod.dart