tarsier_env 1.0.0
tarsier_env: ^1.0.0 copied to clipboard
A Dart/Flutter package for loading `.env` files and simplifies the management of environment variables and helps automate the process of accessing them within your project.
tarsier_env #
A Dart/Flutter package for loading .env files and generating a Dart file containing environment variables with static getters. This package simplifies the management of environment variables and helps automate the process of accessing them within your project.
Features #
- Loads
.envfiles and parses them into aMap<String, String>. - Generates a
env.dartfile with static getters for each environment variable. - Automatically inserts the import statement and
Env.init()initialization inmain.dart. - Supports custom paths for the
env.dartfile.
Installation #
1. Add Dependency #
Add the following to your pubspec.yaml file:
dependencies:
tarsier_env: ^1.0.0
Then run this command:
flutter pub get
Commands #
The dart run tarsier_env <command> <optional> syntax maps directly with required commands (generate, new). Optional is when you use command generate for custom path.
- Generates a default
.envfile with basic content, including a placeholder for your app name. Automatically checks if.envis listed in.gitignoreand adds it if not already present.
dart run tarsier_env new
This will generate a .env file in the root directory with the following content:
# AUTO-GENERATED FILE.
# YOU CAN EDIT/ADD MORE KEYS AND ITS VALUE.
# Generated by tarsier_env script.
APP_NAME="Tarsier"
APP_ENV=local
APP_KEY=null
APP_DEBUG=true
APP_URL=http://localhost
...
-
Generates a
env.dartfile containing static getters for environment variables from your.envfile. Automatically importsenv.dart. Insertsawait Env.init();in the main() function ofmain.dart.- If no path is provided, the generated file will be placed in
lib/env.dart. - If a relative path under the
libdirectory is provided, the file will be placed in the corresponding subfolder.
- If no path is provided, the generated file will be placed in
dart run tarsier_env generate common/environment
This will create lib/common/environment/env.dart with the environment. After running above code, you can access the environment variables in your Flutter app as follows:
In your main.dart, ensure the Env.init() method is called before using any environment variable.
License #
This package is licensed under the MIT License.
Suggestions for Improvement? #
Feel free to open an issue or submit a pull request on GitHub.
Why "Tarsier ENV"?
The tarsier, one of the smallest primates, symbolizes simplicity and adaptability—just like this package! 🐒