flutter_dotenv 2.0.3

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

changelog #

This project follows pub-flavored semantic versioning. (more)

Release notes are available on github.

2.0.3 #

  • [fix] Warning when using with flutter_test

2.0.2 #

  • [fix] Flutter 1.9.5 compatibility ensure binding was initialized

2.0.1 #

  • [docs] tweak app description
  • [fix] increase meta version range

2.0.0 #

  • Flutter compatible

1.0.0 #

  • Dart 2 compatible. [#16][]

0.1.3+3 #

  • [docs] tweak README

0.1.3+2 #

  • [fix] don't throw if load fails [#11][]

0.1.3+1 #

  • [fix] allow braces with ${var} substitution [#10][]

0.1.3 #

  • [new] add command-line interface [#7][], [#8][]
  • [deps] add args@v0.13

0.1.2 #

  • [new] support variable substitution from Platform.environment [#6][]
  • [deps] drop logging

0.1.1+2 #

  • [fix] don't strip # inside quotes [#5][]

0.1.1+1 #

  • [fix] whitespace causes quotes not to be stripped

0.1.1 #

  • [deprecated] Parser internals will become private. [#3][]
    • #unquote, #strip, #swallow, #parseOne, #surroundingQuote, #interpolate
  • [new] support variable substitution
  • [deps] migrate to test
  • [deps] bump logging

0.1.0 #

Initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_dotenv: ^2.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_dotenv/flutter_dotenv.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
92
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Sep 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flutter_dotenv.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.7
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test