flutter_dotenv 6.0.1
flutter_dotenv: ^6.0.1 copied to clipboard
Easily configure any flutter application with global variables using a `.env` file.
changelog #
This project follows pub-flavored semantic versioning. (more)
Release notes are available on github.
6.0.1 #
- [fix]
isEveryDefined()now throwsNotInitializedErrorbeforeload(), consistent with all other read APIs - [fix] Replace
assert()with explicitif/throwingetInt(),getDouble(), andgetBool()so null-safety checks are enforced in release builds - Error messages now include the variable name for easier debugging
- [fix]
load(isOptional: true)no longer discards successfully loaded base file when an override file is missing or empty (fixes #70, #93, #101, #125) - [fix]
clean()now resetsisInitializedtofalse, so accessingenvafterclean()correctly throwsNotInitializedError - [fix] Error classes (
NotInitializedError,FileNotFoundError,EmptyEnvFileError) now include informative messages intoString()instead of the unhelpfulInstance of 'ClassName'(fixes #72, #127; improves diagnostics for #59, #89) FileNotFoundErrorandEmptyEnvFileErrornow carry the filename when available
Note on error message improvements #
NotInitializedError, FileNotFoundError, and EmptyEnvFileError now override toString() with actionable messages (e.g., FileNotFoundError: Environment file ".env" not found. Ensure the file exists and is listed under assets in pubspec.yaml.). This is not a breaking change — the class names and hierarchy are unchanged, so existing on FileNotFoundError catch clauses continue to work. FileNotFoundError now accepts an optional positional filename parameter, and EmptyEnvFileError accepts an optional named filename parameter; both default to null for backward compatibility.
Note on release-build behavior change #
In debug mode, behavior is unchanged — AssertionError was thrown before, AssertionError is thrown now.
In release mode, calling getInt(), getDouble(), or getBool() with a missing variable and no fallback previously threw a TypeError (from the null-check operator !) because assert() was stripped. It now correctly throws AssertionError with a descriptive message. If your release-mode code catches on TypeError around these methods, update it to catch on AssertionError (or on Error) instead.
Breaking change: clean() now resets initialization state #
Previously, calling clean() only cleared the env map but left isInitialized == true. Now it also sets isInitialized = false. Code that calls clean() and then immediately accesses dotenv.env without reloading will now throw NotInitializedError. The fix is to call load() or loadFromString() again after clean().
6.0.0 #
- [feat] Allow passing in override .env files on init
- [feat] Load .env from a passed in string
Breaking changes #
-
Renamed:
testLoad→loadFromString
The method has been renamed to better reflect that it can be used outside of test environments.
⚠️ Update your code to callloadFromString()instead oftestLoad(). -
Behavior change: Empty file handling with
isOptional = true
Previously, if the env file was empty andisOptionalwastrue, the method would throw.
Now, in this case, it no longer throws and simply returns an empty env. -
Supported SDK range change: Dropped support for the pre release
2.12.0-0. Now supports2.12.0onwards.
5.2.1 #
- [chore] Update readme with security info and new usage examples
5.2.0 #
- [new] Get variables as
int,doubleandbool - [deps] Upgrade dart sdk constraints to
>=2.12.0-0 <4.0.0 - [new] Export error classes
5.1.0 #
- [new] Add
isOptionalinit param to prevent throwing if env file is not found - [new] variable name in error message
5.0.1 #
- [fix] Change
testLoad()to be synchronous - [new] Add
get()andmaybeGet()methods for getting values with a fallback
5.0.0 #
- [BREAKING] Wrap dotenv.dart methods within a class
- [fix] Updated documentation to reflect changes and improve clarity
Upgrading from 4.0.x #
- Access dotenv methods from the DotEnv class instead of globally.
- Prepend dotenv to all dotenv method calls: e,g,
load()todotenv.load().
4.0.0-nullsafety.1 #
- [fix] Remove lookbehind regex to support safari browser
4.0.0-nullsafety.0 #
- [BREAKING] Opt into null-safety
- [deps] Upgrade dart sdk constraints to
>=2.12.0-0 <3.0.0 - [new] Allow for escape of $ ' " and \n characters
- [fix] Ensure swallow function only removes leading 'export' keyword
- [fix] Retain spaces within single or double quotes
- [fix] Allow for comments after matching end quotes
- [new] Migrate to null safety
- [new] Create unit test cases for parse
3.1.0 #
- [new] Allow merging with a custom map on load
3.0.2 #
- [chore] Format code with dart fmt
3.0.1 #
- [docs] Use secure links
3.0.0 #
- [new] Merge with Platform.Environment
- [new] Throw precise errors
- [new] Access via functions
- [new] Improved Parsing
- [docs] Example project
2.1.0 #
- [new] Support '=' sign in value
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 #
0.1.0 #
Initial release.