Last updated:
0 purchases
flutter dd cli
flutter_dd_cli #
A helper CLI Utility to simplify usages of Dart Defines.
Features #
Generates a string of formatted --dart-defines ready to be pasted into any flutter build and flutter run commands.
Simplify flutter build command by specifying an existing file containing ready-to-inject values (in json or line separated), converting them to --dart-define format.
Provides an alternative way instead of editing .vscode/launch.json or .idea/workspace.xml directly.
Getting started #
Installation #
flutter pub global activate flutter_dd_cli
copied to clipboard
If you have direct access to pub in your PATH then you can omit the flutter prefix.
The CLI will be available as the terminal command fdd. But in order to use it everywhere, e.g on your current Flutter project directory, you have to add the system cache bin directory to your PATH environment variable.
Assuming the Flutter installation is located at the default location, here are some known possible PATHs:
MacOS/Linux Path:
$HOME/.pub-cache/bin
copied to clipboard
Windows Path:
%LOCALAPPDATA%\Pub\Cache\bin
copied to clipboard
Usage #
Generate Dart Defines #
From JSON File
Given the sample JSON File below with name env.json
{
"log": true,
"apiKeyA": "NeverGonnaGiveYouUp",
"apiKeyB": "NeverGonnaLetYouDown",
"apiKeyC": "NeverGonnaRunAround",
"protocol": "and",
"baseUrl": "Deserts.You",
"port": 420
}
copied to clipboard
Assuming env.json is currently located at current working directory
fdd generate json env.json
# or if the file is located somewhere else
fdd generate json /path/to/env.json
copied to clipboard
From Formatted Env File
For this method, the env file is expected to be in this format, read line by line:
log=true
apiKeyA=NeverGonnaGiveYouUp
apiKeyB=NeverGonnaLetYouDown
apiKeyC=NeverGonnaRunAround
protocol=and
baseUrl=Deserts.You
port=420
copied to clipboard
Where key consists of alphanumeric and underscores and value consists of String-likes.
# assuming the file name is config
fdd generate env config
# or named debug.old
fdd generate env debug.old
# from somewhere else
fdd generate env /path/to/env
copied to clipboard
Generated Result #
The result is expected to look like this
--dart-define=log=true --dart-define=apiKeyA=NeverGonnaGiveYouUp ...
copied to clipboard
You may copy/pipe the result from your terminal and use it directly on your flutter build/flutter run script or add it into Run/Build Configuration section on Android Studio.
Build with Dart Defines #
The build command will delegate the arguments into flutter build command.
# This will delegate the dart defines into flutter build appbundle --release command
fdd build json env.json appbundle --release
# Delegates to flutter build apk --debug
fdd build env debug.old apk --debug
# Add --clean to run flutter clean before flutter build
fdd build json env.json appbundle --release --clean
# Clean and defaults to --release
fdd build json env.json appbundle --clean
copied to clipboard
Flutter Obfuscation
There is a Flutter command to obfuscate the Dart code using --obfuscate --split-debug-info=... which is optionally available by adding the parameter below.
--obfuscateSplitPath=</path_to/project_name/directory>
copied to clipboard
Outputs
The generated build files are located at the same location defined by flutter build command.
Extra: it also pipes the stdout and stderr from the flutter commands.
Additional information #
Constraints #
Values with spaces are not allowed
Invalid entries are skipped
For referencing an env file, avoid naming the file as env
TODOs #
Integrate flutter run
Add contents for --help / -h arguments
Add more textual Error Messages
Add more Error classes
Code breakdown into smaller classes
Localizations
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.