Sub topic 1
Why one app needs several environments
Prerequisites
This chapter assumes basic Dart and Flutter development, familiarity with flutter run and flutter build, and a basic understanding of API base URLs and app bundle IDs. You should also recognize the android/ and ios/ folders in a Flutter project.
The problem with one shared configuration
A Flutter app usually talks to services outside the app. It may call an API, send crash reports, read feature flags, or connect to Firebase. These services often need different settings during development and release.
A development environment is used while building features. It might contain test data and accept frequent changes. A staging environment is used for team testing. It should resemble production but remain separate from real users. Production is the released environment and contains real data.
The Dart and Flutter code can stay mostly the same across these environments. The configuration around that code changes.
| Setting | Development | Staging | Production |
|---|---|---|---|
| API base URL | Test API | Release candidate API | Live API |
| Data | Disposable test data | Shared test data | Real user data |
| Logging | Detailed | Detailed enough to diagnose | Reduced |
| App identity | MyApp Dev | MyApp Staging | MyApp |
Without separation, a developer can accidentally point a local build at production. A test could create unwanted real records, or a new feature could expose incomplete behavior to users. Separate environments reduce these mistakes by making the target explicit.
A useful mental model
Think of an environment as a named set of decisions around one application:
- Which backend should this build call?
- Which logging and analytics settings should it use?
- Which app name and identifier should the operating system display?
- Which service configuration and assets belong to it?
- Which signing identity is allowed for its release?
The environment is not a second copy of the application. It is a selection of configuration and native settings used with the shared codebase.
A build can combine several mechanisms. Compile-time values provide settings to Dart. Separate entrypoints can construct the app with a chosen configuration. Native flavors, schemes, and build configurations give the installed application its platform-specific identity.
The Dart configuration and the native configuration must agree. If Dart uses the staging API but Android or iOS labels the app as production, the mismatch can confuse testers and increase operational risk.
Choose separation based on risk
Not every project needs three environments on its first day. A small prototype may need only development and production. Add staging when several people need to test release candidates, when production data must be protected, or when native integrations need realistic testing.
Keep environment names consistent across Dart, Android, iOS, launch configurations, and CI. For example, use dev, staging, and prod everywhere instead of mixing development, qa, and release.
A good setup makes the selected environment visible. Use a different app name or icon for non-production builds, and show the environment in an internal diagnostics screen. These signals make it harder to mistake a test build for the live app.
The next chapters show how to pass these choices into Dart and how native flavors connect the choices to installed applications.
Exercise
Why should a staging build use a separate API and app identity instead of only changing a label inside the app?
Show answer
A separate API protects production data, while a separate app identity makes the build visible and allows it to be installed and managed independently.