πŸš€ Flutter Flavors – The Secret to Production-Grade Apps

When building apps for production, you cannot rely on a single environment.
You need to separate development, staging, and production – each with its own Firebase configs, API URLs, and app IDs.

That’s where Flavors in Flutter come in.

πŸ”Ή Why Flavors are Important?

βœ… Keep API endpoints separate (dev vs staging vs prod).
βœ… Manage Firebase projects for each environment.
βœ… Test safely before shipping to real users.
βœ… Automate configs β†’ fewer manual mistakes.
βœ… Professional workflow for production-ready apps.

πŸ”Ή Step 1: Add Package

Install flutter_flavorizr (saves tons of manual work):

dev_dependencies:
  flutter_flavorizr: ^2.1.4

Run:

flutter pub get

πŸ”Ή Step 2: Setup Firebase Configs

Organize Firebase files per environment:

assets/firebase/
  β”œβ”€β”€ development/
  β”‚    β”œβ”€β”€ google-services.json
  β”‚    └── GoogleService-Info.plist
  β”œβ”€β”€ staging/
  β”‚    β”œβ”€β”€ google-services.json
  β”‚    └── GoogleService-Info.plist
  └── production/
       β”œβ”€β”€ google-services.json
       └── GoogleService-Info.plist

πŸ”Ή Step 3: Add Config JSONs

Inside assets/config/ create environment configs:

πŸ‘‰ config.development.json
πŸ‘‰ config.staging.json
πŸ‘‰ config.production.json

Example:

{
  "FLAVOR": "development",
  "GOOGLE_AUTH_CLIENT_ID": "1:889331959331:android:cd1780b696d94127fd1396.apps.googleusercontent.com",
  "BASE_URL": "https://api-dev.roccovideo.com"
}

πŸ”Ή Step 4: Configure flavorizr.yaml

Here’s a full example πŸ‘‡

app:
  android:
    flavorDimensions: "flavor-type"

flavors:
  development:
    app:
      name: "RB Dev"
    android:
      applicationId: "dev.rblive.com"
      icon: "assets/launcher/launcher_icon.png"
      firebase:
        config: "assets/firebase/development/google-services.json"
    ios:
      bundleId: "dev.rblive.com"
      icon: "assets/launcher/launcher_icon.png"
      firebase:
        config: "assets/firebase/development/GoogleService-Info.plist"

  staging:
    app:
      name: "RB Staging"
    android:
      applicationId: "staging.rblive.com"
      icon: "assets/launcher/launcher_icon.png"
      firebase:
        config: "assets/firebase/staging/google-services.json"
    ios:
      bundleId: "staging.rblive.com"
      icon: "assets/launcher/launcher_icon.png"
      firebase:
        config: "assets/firebase/staging/GoogleService-Info.plist"

  production:
    app:
      name: "RB Live"
    android:
      applicationId: "pro.rblive.com"
      icon: "assets/launcher/launcher_icon.png"
      firebase:
        config: "assets/firebase/production/google-services.json"
    ios:
      bundleId: "prod.rblive.com"
      icon: "assets/launcher/launcher_icon.png"
      firebase:
        config: "assets/firebase/production/GoogleService-Info.plist"

ide: vscode

instructions:
  - assets:download
  - assets:extract
  - android:icons
  - android:androidManifest
  - android:buildGradle
  - ios:xcconfig
  - ios:buildTargets
  - ios:schema
  - ios:icons
  - ios:plist
  - assets:clean

πŸ”Ή Step 5: Generate Flavors

πŸ‘‰ For Firebase setup:

dart run flutter_flavorizr -p google:firebase

πŸ‘‰ For flavor configs:

dart run flutter_flavorizr -p android:buildGradle,android:flavorizrGradle,android:androidManifest

πŸ”Ή Step 6: Run the App with Flavors

flutter run --flavor development -t lib/main_development.dart
flutter run --flavor staging -t lib/main_staging.dart
flutter run --flavor production -t lib/main_production.dart

πŸ† Final Thoughts

With Flutter Flavors, you:

  • Keep environments clean πŸ”‘
  • Avoid config mixups 🚫
  • Deliver production-grade apps like a pro βœ…

πŸ‘‰ If you’re serious about publishing apps at scale, Flavors are not optional – they’re essential.

#Flutter #MobileDevelopment #Firebase #AppDevelopment #FlutterFlavors #ProductionReady

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top