flutter_dotenv 2.1.0 copy "flutter_dotenv: ^2.1.0" to clipboard
flutter_dotenv: ^2.1.0 copied to clipboard

outdated

Easily configure any flutter application with global variables using a `.env` file.

flutter_dotenv #

Load configuration at runtime from a .env file which can be used throughout the applicaiton.

About #

This library is a fork of mockturtl/dotenv dart library with slight changes to make this work with flutter. It parses the .env file into a map contained within a singleton which allows the variables to be used throughout your application.

Usage #

Create a .env file in the root of your project with the example content:

VAR_NAME=HELLOWORLD

Add the .env file to your assets bundle in pubspec.yaml

  assets:
    - .env

Add the .env file as an entry in your .gitignore if it isn't already

.env*

Init the DotEnv singleton in main.dart

Future main() async {
  await DotEnv().load('.env');
  //...runapp
}

Access variables from .env throughout the applicaiton

DotEnv().env['VAR_NAME'];

Optionally you could map DotEnv().env after load to a config model to access config with types.

Discussion

Use the issue tracker for bug reports and feature requests.

Pull requests are welcome.

Prior art
license: MIT
1795
likes
30
pub points
100%
popularity

Publisher

unverified uploader

Easily configure any flutter application with global variables using a `.env` file.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on flutter_dotenv