Env Reader

0

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—sp…

Productivity

dart
dotenv
env
environment

Env Reader

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. ??️

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.
    API_KEY=VYIUJ7tLdJFqrBesnOJEpkbceBB5GNz0t1aYgHxK3BMxbJOc/g==
    DEBUG=true
    PORT=8080
    DATABASE_URL=postgresql://user:password@localhost:5432/mydb
    
  2. Run the command
    After laying down the foundation, it's time to secure your .env by executing this command in your terminal:
    dart run env_reader --input=".env" --password="MyStrongPassword" --model="lib/src/env_model.dart" --null-safety
    
    Behold 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.
    The result? A triumphant message like this:
    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 ?
    
  3. Loading your encrypted .env
    Load the env_reader instance, after ensuring your WidgetsFlutterBinding was initialized:
    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(...);
    }
    
  4. Access your configuration
    And now, the moment of truth. Access your configuration values with ease:
    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 ?",
    );
    

Env Reader Command ?

Company Screenshot