🌿 envified

pub package pub points License: MIT Dart CI Sponsor

Stop rebuilding. Start switching. ⚑
Runtime environment magic for Flutter apps. No hot reload needed.


The Problem

You're a Flutter developer. Every time you need to test a different API endpointβ€”local dev server, staging, productionβ€”you rebuild the app. With --dart-define flags. Or .env files baked into the binary. Or multiple entry points. It's tedious. It's error-prone. It breaks flow.

What if you could swap environments in 0.2 seconds? No rebuild. No compilation. Just tap, tap, done.

That's envified.


What is envified?

envified is a production-grade environment manager for Flutter that lives entirely at runtime.

  • πŸš€ Swap dev ↔ prod in 200ms β€” no rebuild, no hot reload
  • πŸ”„ Smart Restart Detection β€” know when dependencies need re-initialization
  • πŸ”’ Prod lock by default β€” prevent accidental data disasters
  • πŸ” Sensitive Data Protection β€” automatic blurring of API keys and tokens
  • πŸ§ͺ Override any URL β€” test against local tunnels, PR branches, anywhere
  • πŸ›‘οΈ Premium PIN gate β€” secure the debug panel with modern UI
  • πŸ“‹ Full audit trail β€” visual timeline of every switch and URL change
  • βš™οΈ Zero production overhead β€” stripped out entirely in release builds
  • 🎨 Enterprise UX β€” premium card-based design with dark mode support

It's not just a config switcher. It's enterprise-grade security meets developer quality of life.

Note

Security Note: While envified encrypts the active configuration state and overrides on the device (via Keychain/Keystore), the base .env files stored in your Flutter assets remain plaintext. Never store high-stakes production secrets directly in .env files; they should be fetched at runtime from a secure vault or used for non-sensitive configuration only.


πŸš€ What's New in v3.2.2

Building on the foundation of v3.2.0, we've improved reliability and persistence:

Feature What it does
πŸ”„ Per-Env Overrides Custom URLs are now tracked independently for each environment, ensuring they are remembered when switching back and forth.
πŸ—οΈ Robust Extraction Improved .env parser handles whitespace, quotes, and comments more reliably for BASE_URL extraction.
πŸ›‘οΈ Persistence 2.0 Enhanced EnvStorage ensures custom settings aren't lost during app restarts or migrations.
πŸš₯ Smart Fallbacks Fixed priority logic where empty local values would incorrectly block global .env fallbacks.

πŸ“¦ Features

Feature What It Does Why You Care
Smart Restart Detects when env changes require restart Prevents connection/state caching bugs
Data Protection Blurs sensitive keys (API_KEY, etc.) Security in screenshots & screen shares
Auto-Discovery Scans assets for .env.* files Zero config; just add a file and it works
Alias Support Handles dev, stag, production, etc. Follows industry standard naming conventions
Tamper Detection SHA-256 hashes .env* files Catch rogue config changes on rooted devices
Access Gate Modern PIN dialog before opening panel QA devices don't leak sensitive switches
URL Validation Live feedback on custom API URLs Prevent typos and invalid endpoint formats
Audit Log Vertical timeline of every switch "Who changed prod at 3pm?"
Status Badge Persistent [DEV] indicator in your app Never forget what env you're testing
Gesture Triggers Tap N times, shake, or swipe edge to open Access the panel your way

Quick Start (3 Steps)

1️⃣ Install

dependencies:
  envified: ^3.2.2

Then run:

flutter pub get

No build_runner. No code gen. No magic incantations. Just a package that installs like a normal package. Revolutionary, we know.


2. Create Your Environment Files

Drop these into assets/env/:

assets/
└── env/
    β”œβ”€β”€ .env.dev
    β”œβ”€β”€ .env.staging   ← optional, but you probably want it
    └── .env.prod

Each file is a plain .env file. Nothing exotic:

# .env.dev
BASE_URL=https://dev.api.myapp.com
API_KEY=sk_test_51Mz...

# .env.prod
BASE_URL=https://api.myapp.com
API_KEY=sk_live_92A...

Register in pubspec.yaml:

flutter:
  assets:
    - assets/env/

3️⃣ Initialize

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await EnvConfigService.instance.init(
    defaultEnv: Env.dev,
    onAfterSwitch: (config) {
      // Listen for restart needed
      EnvConfigService.instance.restartNeeded.addListener(() {
        debugPrint('Dependencies must re-initialize');
      });
    },
  );

  runApp(const MyApp());
}

Wrap your app with the overlay:

MaterialApp(
  builder: (context, child) => EnvifiedOverlay(
    service: EnvConfigService.instance,
    enabled: kDebugMode,
    gate: EnvGate(pin: '1234'),
    onRestart: () {
      // Trigger a hard restart (e.g. using phoenix or SystemNavigator)
      SystemNavigator.pop();
    },
    child: child!,
  ),
  home: const MyHomePage(),
)

πŸ”’ Production Locking β€” The Guardian Angel

Two scenarios where production locking saves you:

Scenario A β€” Release builds
**Set allowProdSwitch: false and pass enabled: false to EnvifiedOverlay. The panel is gone. The service ignores switch attempts. Your prod build is clean and your users have no idea any of this exists.

Scenario B β€” The brave "always prod" setup
Maybe you want the panel available in staging but default to Prod and lock it there:

await EnvConfigService.instance.init(
  defaultEnv: Env.prod,
  allowProdSwitch: false, // once you're in Prod, you stay in Prod
);

Now, if anyone (your QA lead, your over-curious intern, your past self at 11 PM) tries to switch away, they get a loud EnvifiedLockException and a UI that has already greyed out the controls. The audit log records the attempt. The blame is documented.

// Catching the exception if you need to handle it gracefully:
try {
  await EnvConfigService.instance.switchTo(Env.dev);
} on EnvifiedLockException catch (e) {
  showDialog(
    context: context,
    builder: (_) => AlertDialog(
      title: const Text('Nice try.'),
      content: Text(e.message),
    ),
  );
}

πŸ” Reading Values

Once initialized, getting a value is a single line:

final svc = EnvConfigService.instance;

// String (use .get)
final apiUrl = svc.get('API_URL');

// Boolean (use .getBool)
final debugMode = svc.getBool('DEBUG', fallback: false);

// Integer (use .getInt)
final timeout = svc.getInt('API_TIMEOUT', fallback: 30);

Troubleshooting

Q: "No .env.* files discovered"

Cause: Asset files not registered in pubspec.yaml

Fix:

flutter:
  assets:
    - assets/env/

Run: flutter clean && flutter pub get

Q: Environment switches but API still hits old endpoint

Cause: HTTP client cached the URL at startup

Fix: Tap "Restart now" in the debug panel to re-initialize or listen to restartNeeded.


Integration with HTTP Clients

Dio

import 'package:dio/dio.dart';
import 'package:envified/envified.dart';

final dio = Dio();

Future<void> setupDio() async {
  await EnvConfigService.instance.init();
  
  // Set initial base URL
  dio.options.baseUrl = EnvConfigService.instance.current.value.baseUrl;
  
  // Listen for environment changes
  EnvConfigService.instance.current.addListener(() {
    dio.options.baseUrl = EnvConfigService.instance.current.value.baseUrl;
  });
}

API Stability & Versioning

Semantic Versioning

This package follows Semantic Versioning:

  • MAJOR (1.0.0) β€” Breaking changes to public API
  • MINOR (0.1.0) β€” New features, backwards compatible
  • PATCH (0.0.1) β€” Bug fixes, backwards compatible

πŸ’š Support & Sponsorship

envified is free and open source, built with β˜• by Sumit Pal (@appamania).

Tier Link What it buys
β˜• A sip of chai β‚Ή20 You liked the package
🍡 A full cup β‚Ή50 It saved you real time
πŸš€ Keep the lights on β‚Ή100 You ship with it in prod

Buy me a Chai

🀝 Contributing

We welcome all contributions! Please read CONTRIBUTING.md before opening a PR.

πŸ“„ License

MIT Β© Appamania

Libraries

envified
envified β€” Runtime environment switching for Flutter.