[!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