Build Flavors and Environment Configuration
Define dev, staging, and prod flavors with per-environment assets and Dart-define configs.
Why Build Flavors Matter
A production Flutter app rarely talks to a single backend. You need a dev build pointing at a local or staging API, a staging build for QA, and a hardened prod build for the store.
- Flavors are named build variants that can differ in app id, icon, name, and signing.
- Environment config is the data each flavor injects: base URLs, feature flags, API keys.
The goal: install dev, staging, and prod side-by-side on one device, each fully isolated and impossible to confuse.
The Two Layers: Native Flavors + Dart-Define
A clean setup separates two concerns:
- Native flavors (Android
productFlavors, iOSschemes/xcconfig) control the application identity: bundle id, display name, icon. - Dart-define values control runtime configuration your Dart code reads: API URL, environment name, log level.
Native flavors let dev, staging, and prod coexist on the device with distinct ids like com.acme.app.dev. Dart-define keeps secrets and URLs out of source control and version-pinned at compile time.
All lessons in this course
- Build Flavors and Environment Configuration
- Automated Pipelines with Fastlane and GitHub Actions
- Crash Reporting and Symbolicated Stack Traces
- Remote Config, Feature Flags, and Staged Rollouts