Productivity
Enhance the rock-solid integrity of your .env configuration by seamlessly encrypting and decrypting data sourced from a dynamic range of origins—be it assets, files, strings, memory, or networks—spanning a multitude of platforms. What's more, experience the sheer simplicity of generating Dart models directly from your .env data. Your configuration, fortified and efficient, ready to elevate your development journey. ??️
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
Now elevate your development experience with these straightforward steps:
API_KEY=VYIUJ7tLdJFqrBesnOJEpkbceBB5GNz0t1aYgHxK3BMxbJOc/g== DEBUG=true PORT=8080 DATABASE_URL=postgresql://user:password@localhost:5432/mydb
dart run env_reader --input=".env" --password="MyStrongPassword" --model="lib/src/env_model.dart" --null-safetyBehold as the command weaves its magic, turning your .env into a versatile asset, accessible across platforms. It's by default meticulously stored at assets/env/.env, fortifying your configuration for app empowerment.
Building package executable... (1.3s) Built env_reader:env_reader. .env successfully generated into lib/src/env_model.dart ? .env successfully encrypted into assets/env/.env ?
import 'package:env_reader/env_reader.dart'; Future main(List arguments) async { WidgetsFlutterBinding.ensureInitialized(); await Env.load( source: EnvLoader.asset('assets/env/.env'), password: "MyStrongPassword"); // Or you can load raw .env by calling this function await Env.loadExposed( source: EnvLoader.network( Uri.parse('https://my.repo.dir/sub/.env'))); runApp(...); }
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("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 earlier Text( text: EnvModel.debug ? "? pssst, this is my api key y'all \n\n ${EnvModel.apiKey}" : "Nothing to see here ?", );