Package selection guidance compiled from public package information, community data, and project usage.
env_reader is a Dart package that enables secure handling of environment variables by reading, encrypting, or generating them from a .env file. It transforms these variables into an obfuscated Dart model, enhancing security by preventing exposure of sensitive data. Designed for use across multiple platforms, it supports Android, iOS, Web, macOS, Windows, and Linux. The package integrates seamlessly with Flutter projects via a simple pub add command. Ideal for developers prioritizing configuration security in production and development environments.
Use cases
Securely managing API keys
Protecting database credentials
Handling app secrets in CI/CD pipelines
Enabling encrypted configuration files
Safely sharing environment settings
Automating environment variable generation
Key features
Reads .env files securely
Encrypts environment variables
Generates obfuscated Dart models
Supports multi-platform deployment
Provides easy integration via pub
Offers encryption and decryption utilities
Suitable for
Developers focused on app security
Teams using environment-based configurations
Projects requiring secret management
Flutter apps with sensitive data
CI/CD workflows needing secure env handling
Apps deploying across multiple platforms
Considerations
Requires proper encryption key management
Initial setup involves configuration steps
Obfuscation does not replace full encryption
Not suitable for highly dynamic runtime secrets
Depends on external .env file presence
May require additional build process steps
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
Env Reader
Read, encrypt, or generate environment variables from .env file into an obfuscated Dart model.
Features 🚀
Automated Generation: Transform your .env files into dynamic Dart models directly. No need to add annotation. ✨
Seamless Integration: Directly update your pubspec.yaml and .gitignore on command. No need manual labor. 🛠️
Fortified Encryption: Shield your precious .env configurations with an encryption. Say no to prying eyes.🔒
Data Diversity Unleashed: Whether they're integers, decimals, booleans, or strings. Automatic interpretation is at your service. 🎮
Versatile Sourcing: Load your .env from various sources: assets, files, memory, network, and strings. The choice is yours. 🔄
Install 🚀
Get started with these quick commands:
🔥 Add env_reader to your pubspec.yaml with a single line:
dart pub add env_reader
✨ Unlock the magic by activating the env_reader CLI:
dart pub global activate env_reader
Usage 🚀
Now elevate your development experience with these straightforward steps:
1. Set up your configuration
Start by crafting your .env file in the root directory of your project, right alongside your trusty pubspec.yaml.
[!NOTE]
output: .env successfully generated into lib/src/env_model.dart 🎉
3. Loading your .env
Load the env_reader instance:
import'package:env_reader/env_reader.dart';
import'package:flutter/services.dart';
awaitEnv.load(
EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
"MyOptionalSecretKey");
// Or you can load by creating your own `EnvReader` instance.EnvReader production = EnvReader();
await production.load(
EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
"MyOptionalSecretKey");
4. Access your configuration
To get and read the value of your env:
import'package:env_reader/env_reader.dart';
import'package:my_package/src/env_model.dart';
String api = Env.read("API_KEY") ?? "Got'cha 😎";
bool debug = Env.read<bool>("DEBUG") ?? false;
// If you make your own instance, call it like thisString api = production.read("API_KEY") ?? "Got'cha 😎";
bool debug = production.read<bool>("DEBUG") ?? false;
Text(
text:
debug ? "🤫 pssst, this is my api key y'all \n\n $api" : "Nothing to see here 🤪",
);
// Or you can access the value directly from env generated model earlierText(
text:
EnvModel.debug ? "🤫 pssst, this is my api key y'all \n\n ${EnvModel.apiKey}" : "Nothing to see here 🤪",
);
Env Reader Command 🚀
Available commands:
Flag
Description
-i, --input (mandatory)
Input path of the .env file
-o, --output
Output path for the encrypted .env file
-s, --key
Secrey key for encryption & decryption
--model
Generate dart model file to your desired file path