Load environment variables at runtime from a .env
file.
NB: Travis uses test_runner
, which has not yet moved off unittest
.
Prefix the library import and call load()
, exposing the env
map
with a top-level getter.
import 'package:dotenv/dotenv.dart' as dotenv;
Map<String, String> get _env => dotenv.env;
void main() {
dotenv.load();
var x = _env['foo'];
// ...
}
Verify required variables are present:
const _requiredEnvVars = const ['host', 'port'];
bool get hasEnv => dotenv.isEveryDefined(_requiredEnvVars);
Variable substitution and character escaping is a work in progress. Some cases don't work yet. Pull requests gleefully considered.
This project follows pub-flavored semantic versioning. (more)
Release notes are available on github.
#
inside quotes #5Parser
internals will become private. #3#unquote
, #strip
, #swallow
, #parseOne
, #surroundingQuote
, #interpolate
Initial release.
example/example.dart
import 'package:dotenv/dotenv.dart' as dotenv;
import 'package:logging/logging.dart';
get env => dotenv.env;
final log = new Logger('example');
void main() {
_config();
dotenv.load();
log.info('main: value of foo is ${env['foo']}');
log.info('main: value of baz is ${env['baz']}');
log.info('main: your home directory is: ${env['HOME']}');
}
void _config() {
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name} ${_toMsg(rec)}');
});
}
String _toMsg(LogRecord rec) =>
'${rec.time}: [${rec.loggerName}] ${rec.message}';
Add this to your package's pubspec.yaml file:
dependencies:
dotenv: ^0.1.2
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:dotenv/dotenv.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.0.0 | Jul 12, 2018 |
|
|
0.1.3+3 | Jul 19, 2015 |
|
|
0.1.3+2 | Jun 5, 2015 |
|
|
0.1.3+1 | May 15, 2015 |
|
|
0.1.3 | May 15, 2015 |
|
|
0.1.2 | May 12, 2015 |
|
|
0.1.1+2 | May 10, 2015 |
|
|
0.1.1+1 | May 10, 2015 |
|
|
0.1.1 | May 10, 2015 |
|
|
0.1.0 | Apr 7, 2015 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
80
|
Health:
Code health derived from static analysis.
[more]
|
--
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
--
|
Overall:
Weighted score of the above.
[more]
|
40
|
This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Running dartdoc
failed. (-10 points)
Make sure dartdoc
runs without any issues.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.8.0 <2.0.0 |