- January 28, 2026
- maulik.jadvani@gmail.com
- 0
🚀 Running Dev, Staging & Production from a Single Flutter Codebase Using Flavors
Flutter Flavors allow you to manage multiple environments (Dev, Staging, Production) in one project — each with different app names, API endpoints, and configuration, while keeping a single codebase.
🟢 Step 1 — Create Environment Config in Flutter
Create a configuration class that holds the values for each environment. Make it globally available so you can read appConfig.baseUrl anywhere in the app.
class AppConfig {
final String appName;
final String baseUrl;
const AppConfig({
required this.appName,
required this.baseUrl,
});
}
late AppConfig appConfig;
Create Separate Entry Points
📁 lib/main_dev.dart
import 'package:flutter/material.dart';
import 'core/config/app_config.dart';
import 'app.dart';
void main() {
appConfig = const AppConfig(
appName: "MyApp Dev",
baseUrl: "https://dev.api.com",
);
runApp(const MyApp());
}
📁 lib/main_prod.dart
void main() {
appConfig = const AppConfig(
appName: "MyApp",
baseUrl: "https://api.com",
);
runApp(const MyApp());
}
Use the config anywhere in the app:
appConfig.baseUrl
🤖 Step 2 — Android Flavor Setup
Open android/app/build.gradle and add flavor dimensions and product flavors:
flavorDimensions "env"
productFlavors {
dev {
dimension "env"
applicationIdSuffix ".dev"
versionNameSuffix "-dev"
}
staging {
dimension "env"
applicationIdSuffix ".staging"
versionNameSuffix "-staging"
}
prod {
dimension "env"
}
}
🍏 Step 3 — iOS Flavor Setup
Open ios/Runner.xcworkspace in Xcode and do the following:
- Duplicate the Runner scheme (Runner‑Dev, Runner‑Staging, Runner‑Prod)
- Create build configurations: Debug‑dev / Release‑dev, Debug‑staging / Release‑staging, Debug‑prod / Release‑prod
- Set unique bundle identifiers (e.g.
com.company.app.dev)
▶️ Step 4 — Run the App by Flavor
Run your app with the flavor flag and the appropriate entrypoint file:
# DEV
flutter run --flavor dev -t lib/main_dev.dart
# STAGING
flutter run --flavor staging -t lib/main_staging.dart
# PROD
flutter run --flavor prod -t lib/main_prod.dart
Final result: One codebase. Multiple environments. Clean, scalable architecture. 🚀
