I want to create dev mode and prod mode for my app. In Flutter's documentation about flavors, they refer to two packages on pub.dev and a bunch of articles. The flutter_flavor package seemed the easiest to implement so I installed it and I followed the steps mentioned in their documentation. However, I don't know how to actually run the different flavors? It is not mentioned in the package's documentation. They mention adding some configurations to launch.json but I'm not sure what that does and how am I supposed to use it when running the app? Is there a command to run the flavors from the vscode terminal?
The steps I did:
- create two main files;
main_prod.dartandmain_dev.dart - inside
main_dev.dart:
import 'package:flutter/material.dart';
import 'package:flutter_flavor/flutter_flavor.dart';
import 'main.dart';
void main() {
FlavorConfig(
name: "DEV",
color: Colors.red,
location: BannerLocation.topStart,
variables: {
"baseUrl": "https://www.example2.com",
"appTitle": "app1-dev",
},
);
return runApp(MyApp());
}
inside main_prod.dart:
import 'package:flutter/material.dart';
import 'package:flutter_flavor/flutter_flavor.dart';
import 'main.dart';
void main() {
FlavorConfig(
color: Colors.red,
location: BannerLocation.topStart,
variables: {
"baseUrl": "https://www.example2.com",
"appTitle": "app1-dev",
},
);
return runApp(MyApp());
}
- my
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "skinhealthapp",
"request": "launch",
"type": "dart"
},
{
"name": "PROD-Flavor",
"program": "[project-folder]/lib/main_prod.dart",
"request": "launch",
"type": "dart"
},
{
"name": "DEV-Flavor",
"program": "[project-folder]/lib/main_dev.dart",
"request": "launch",
"type": "dart"
}
]
}
Then what?