πΏ envified
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 |
π€ Contributing
We welcome all contributions! Please read CONTRIBUTING.md before opening a PR.
- π Report a Bug
- π‘ Request a Feature
- π Open a Pull Request
π License
MIT Β© Appamania
Libraries
- envified
- envified β Runtime environment switching for Flutter.