dynamic_config_generator 0.5.1
dynamic_config_generator: ^0.5.1 copied to clipboard
Dynamically generate config for a build variant using a json file
dynamic_config_generator #
Generate configuration constants for different environments from a json file.
How to use #
- Create a
config.jsonfile within thetooldirectory which contains the keys for a particular variant (check out the Example section for more) - Execute
dart run build_runner build --define "dynamic_config_generator|config_builder=variant=$variant". The value of the variant would bedebugorreleasefor the example below.
You can supply $variant via an environment variable in your CI setup.
You will need to escape the inverted commas on Windows, so the command becomes
flutter packages pub run build_runner build --define """dynamic_config_generator|config_builder=variant=$variant"""
- This will create
build_config.g.dartin yourlibfolder - Import this file in the relevant classes and use the generated
BuildConfigconstants.
Example #
{
"debug": {
"isRelease": false,
"apiKey": "apiKeyDebug"
},
"release": {
"isRelease": true,
"apiKey": "apiKeyRelease"
}
}
will generate the file build_config.g.dart with the following content if you build for the release variant.
abstract class BuildConfig {
static const isRelease = 'true';
static const apiKey = 'apiKeyRelease';
}