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

Libraries

flutterdotenv