env_builder_cli 1.0.0+1
env_builder_cli: ^1.0.0+1 copied to clipboard
A Flutter CLI tool to automate the creation and maintenance of the env Flutter package from multiple .env files.
Env Builder CLI #
env_builder_cli is a Dart CLI tool designed to automate the creation and maintenance of a Flutter package named env inside a packages/ folder. It helps Flutter developers manage multiple .env environment files by generating Dart code with Envied annotations, updating package dependencies, and managing Flutter project integration seamlessly.
Features #
- Accept multiple
.envfiles (e.g..env.development,.env.production,.env.staging, etc.). - Create the
packages/directory if it does not exist. - Create or update a Flutter package
envwithinpackages/env. - Copy all specified
.env.*files intopackages/env/. - Generate Dart files (
env.dev.dart,env.prod.dart,env.stg.dart, etc.) withinlib/src/. - Generate
lib/src/env.dartexporting all generated environment Dart files. - Create or update
pubspec.yamlinsidepackages/envwith required dependencies. - Automatically modify the root Flutter project’s
pubspec.yamlto includeenvas a path dependency. - Run
flutter pub getautomatically in the root project after setup. - Minimal and clear command-line output.
Prerequisites #
- Dart SDK version 3.8.1
- Flutter SDK installed and added to your system path (for running
fluttercommands). - Your Flutter project root directory (with an existing
pubspec.yaml) contains the.env.*files you want to use.
Installing #
dart run global activate env_builder_cli
Usage #
Create your .env.* files (e.g: .env, .env.development, .env.production, .env.staging, etc) inside your Flutter project's root and specify all your necessaries keys and values inside them.
Ex:
# App settings
BASE_URL = https://api.example.com/
API_KEY = supersecret
# Routes
LOGIN_URL = "login"
REGISTER_URL = "register/user"
Command #
You specify all the .env files that you want to use by separating the with comma.
env_builder --env-file=.env
Or
env_builder --env-file=.env.development, .env.production, .env.staging
Or
env_builder --env-file=.env.development
Wait till env_builder takes care of everything for you.
Now, you can use your environment variables inside your application.
Ex:
/// In development mode, use AppFlavor.development(); => stands for .env.development
/// In production mode, use AppFlavor.production(); => stands for .env.production or .env in case you provide only that one
/// In staging mode, use AppFlavor.staging(); => stands for .env.staging
final appFlavor = AppFlavor.production();
class ApiService {
final appBaseUrl = appFlavor.getEnv(Env.baseUrl);
final apikey = appFlavor.getEnv(Env.apiKey);
}
- In development mode, use
AppFlavor.development(). It stands for .env.development - In production mode, use
AppFlavor.production(). It stands for .env.production or .env in case you provide only that one. - In staging mode, use
AppFlavor.staging(). It stands for .env.staging
NB: you can name you .env.* file whatever you want. But, to call the appropriate AppFlavor, use the word after .env.
Ex:
.env.word ==> AppFlavor.word()