env_reader 1.0.0 copy "env_reader: ^1.0.0" to clipboard
env_reader: ^1.0.0 copied to clipboard

Effortlessly manage and access secured environment variables across Flutter platforms using this dotenv reader.

Env Reader #



Effortlessly manage and access secured environment variables across Flutter platforms using this dotenv reader.

Feature #

  • Simplified Access: Easily load and retrieve environment variables from a .env file using a concise syntax 👌.
  • Secure Handling: Supports encrypted .env files, enhancing security by decrypting sensitive data during loading 🔓.
  • Flexible Value Types: Automatically parses environment values into appropriate data types, such as integers, floating-point numbers, and booleans ðŸ•đ.
  • Streamlined Integration: Integrate the library seamlessly into your Flutter project for all of its platform 🚀.

Install #

Run this command to add env_reader into your pubspec.yaml

dart pub add env_reader

now to activate the command line for env_reader, you gotta run this command

dart pub global activate env_reader

Usage #

First thing to do is making .env file in root directory of your project folder same directory with pubspec.yaml. Also for suggestion add the .env in your .gitignore.

# .env sample file
API_KEY=my-secret-api-key
DEBUG=true
PORT=8080
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

when you've done it, you will need to run this command.

dart run env_reader --path=".env" --password="my strong password"

Notice when you running this command you need to set --password, because this function make the .env file publicly accessible for all platfrom in assets/env/ directory, so atleast you gotta encrypt it right 😉. The --path itself is where your original .env locate, where it will be turn into secured version in assets/env/ path, just like this sample message.

.env successfully secured into assets/env/.env 🚀

so that result path is the asset path where we should set in loading the env_reader instance.

Next step, we need to import this package like this.

import 'package:env_reader/env_reader.dart';

And loading the env_reader instance after ensuring WidgetsFlutterBinding to initialized.

Future<void> main(List<String> arguments) async {
  WidgetsFlutterBinding.ensureInitialized();

  await Env.instance.load(
    asset: "assets/env/.env",
    password: "my strong password");

  runApp(...);
}

After everything has been set, we fetch the value from .env like this

String api = Env.read("API_KEY") ?? "Got'cha 😎";
bool debug = Env.read<bool>("DEBUG") ?? false;

Text(
  text: debug ? "ðŸĪŦ pssst, this is my api key y'all\n\n$api" : "Nothing to see here ðŸĪŠ",
  ),
);

Addition #

Currently this library only support on parsing int, double, bool and String. You can also read the parsed .env in Map<String, dynamic> format by calling this

Map<String, dynamic> json = Env.instance.toJson();

or if you want to see the original content, you can call this

String? env = Env.instance.value;

Example #

23
likes
0
pub points
1%
popularity

Publisher

verified publisherinidia.app

Effortlessly manage and access secured environment variables across Flutter platforms using this dotenv reader.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, encryptor, flutter, universal_file

More

Packages that depend on env_reader