flutter flavours
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
- add package flutter_flavorizr: ^2.0.0 in dev_enviroment
- 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"
- 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 onlyflutter pub run flutter_flavorizr
.
this step add all config in android/app/build.gradle and ios directories to run the flavours - 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.
- 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 - 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
Comments are closed.