🌲Jon Holtan’s Post

View profile for 🌲Jon Holtan, graphic

Chill Bro Developer (CBD) | Uptech Studio | Flutter | Android | iOS | Typescript | Deno | Supabase | Bitrise | DevOps

Take Flutter configurations to the next level with Envied, a .env file and code-gen. Dart-Defines get overwhelming after a certain point and can hinder project setup since then dart-defines and then api keys live in the vscode launch.json. Don't confuse Envied with dotenv, dotenv requires packing your .env into your asset folder and requires an async load at app launch, yuck. Andrea Bizzotto has a great article about this and it is what turned me and my team onto Envied. Envied has truly allowed us to standardize our app build + CI/CD process with the addition of 1Password or Doppler. https://lnkd.in/gsBfssPu

View profile for Andrea Bizzotto, graphic

Flutter GDE, Developer & Instructor at Code With Andrea

Did you know? When you run your Flutter app, you can add a --flavor argument. To get the flavor at runtime, read the FLUTTER_APP_FLAVOR environment variable. This will return a string that you can map to a type-safe enum.

  • To launch your app with a custom flavor, you can run:
flutter run --flavor dev

To get the flavor at runtime and map it to a type-safe-enum, use this code:

enum Flavor { dev, stg, prod }

Flavor getFlavor() {
  const flavorStr = String.fromEnvironment('FLUTTER_APP_FLAVOR');
  return switch (flavorStr) {
    'dev' => Flavor.dev,
    'stg' => Flavor.stg,
    'prod' => Flavor.prod,
    _ => throw UnsupportedError('Unsupported flavor: $flavorStr'),
  };
}

To view or add a comment, sign in

Explore topics