I am not clear your your problem. Because can't see detail of your project structure. As for me I build with flavor as below code and suppose this will help for you.
Firstly build two main entry file for prod and dev.
for PROD flavor
void main() async {
FlavorConfig(
flavor: Flavor.prod,
flavorEnvironment: "Production",
appTitle: "Production",
flavorValues: FlavorValues(
appId: "com.example.production",
baseUrl: BASE_PRODUCTION_URL,
),
);
mainPrimary();
}
for DEV flavor
void main() async {
FlavorConfig(
flavor: Flavor.staging,
flavorEnvironment: "Dev",
appTitle: "Dev",
flavorValues: FlavorValues(
appId: "com.example.dev",
baseUrl: BASE_STAGING_URL,
),
);
mainPrimary();
}
for main file, the entry of project
void mainPrimary() async {
runApp(MyApp());
}
for FlavorConfig file,
class FlavorConfig {
final Flavor flavor;
final FlavorValues flavorValues;
final String environment;
final String appTitle;
static FlavorConfig? _instance;
factory FlavorConfig(
{required Flavor flavor,
required FlavorValues flavorValues,
required String flavorEnvironment,
required String appTitle,}) {
_instance = FlavorConfig._internalConstructor(
flavor: flavor,
flavorValues: flavorValues,
environment: flavorEnvironment,
appTitle: appTitle,
);
return _instance!;
}
FlavorConfig._internalConstructor({
required this.flavor,
required this.flavorValues,
required this.environment,
required this.appTitle
});
static FlavorConfig? get instance => _instance;
static bool _isStagingApp() => _instance?.flavorValues == Flavor.staging;
static bool _isProdApp() => _instance?.flavorValues == Flavor.prod;
}
class FlavorValues {
final String? appId;
final String? baseUrl;
final String? basicToken;
FlavorValues({
this.appId,
this.baseUrl,
this.basicToken,
});
}
enum Flavor { prod, staging }
To change the data depend on flavor, use like that
child: GetMaterialApp(
title: FlavorConfig.instance!.appTitle,
),
As native flavor configure in app/build.grade like that
flavorDimensions "Sample App"
productFlavors{
staging{
dimension "sampleApp"
applicationId "com.example.staging"
versionCode 1
versionName "1.0"
}
prod{
dimension "sampleApp"
applicationId "com.example.production"
versionCode 1
versionName "1.0"
}
}
To run project just type with below command
flutter run --flavor dev -t lib/main_dev.dart
You can set google-services.json for different flavor in by adding in DEV and PROD file.
If above instruction can't help you. You should double check the appId while building project in firebase.
google-services.jsonis not being overwritten during the build process. You can verify this by checking the mergedgoogle-services.jsonin the build output directory.