flutter_dotenv 2.0.1 flutter_dotenv: ^2.0.1 copied to clipboard
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
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
- mockturtl/dotenv (dart)
- bkeepers/dotenv (ruby)
- motdotla/dotenv (node)
- theskumar/python-dotenv (python)
- joho/godotenv (go)
- slapresta/rust-dotenv (rust)
- chandu/dotenv (c#)
- tpope/lein-dotenv, rentpath/clj-dotenv (clojure)
- mefellows/sbt-dotenv (scala)
- greenspun/dotenv (half of common lisp)