config_builder 0.4.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

Pub Package

config_builder #

Build your app config via code generation from .json files. Type-Safe and no unnecessary IO/Parsing on app-startup!

Note: this is an experimental library. Use with caution!

Features #

  • Avoid storing your configuration in dart files
  • Avoid reading config files from disk and parsing them at app start
  • Type safe
  • Supports String, bool, int, double and Enums

How to use #

Add to your devDependencies (see example):

  build_runner: <version>
  config_builder: <version>

Define your configuration model:

part 'config.g.dart'; //use the <filename>.g.dart, where <filename> is the name of this dart file

  ConfigFile(configName: "devConfig", path: ""),
  ConfigFile(configName: "testConfig", path: "config.test.json"),
class Config{
  final String name;
  final int value;
  final Environment environment;

  const Config({, this.value, this.environment});

Make sure the config-class has a const constructor with exclusively named parameters. The generated code will assume that such a constructor exists.

Add your configuration-json file:

  "name" : "devApp",
  "value": 1,
  "environment" : "Dev"

Run the code generation via

flutter packages pub run build_runner build

Now you can access your config object for example via different entry points in your app:

import 'config.dart';

void main() => printConfig(devConfig);


import 'config.dart';

void main() => printConfig(testConfig);

known issues #

  • build_runner caches the result and won't collect changes in your config files if none of your source files changed since the last build I'll look into how this can be fixes. In the meantime, just add a new line somewhere in your config.dart file to force a new build.

[0.4.0+1] #

Lint fixes

[0.4.0] #

Use analyzer ^0.39.0.

[0.3.0] #

Use analyzer ^0.38.0 and newer source_gen versions. built_value and json_serializable support this version by now.

[0.2.0] #

Use analyzer ^0.36.4 in order to be compatible to built_value

[0.1.0] #

Use analyzer >= 0.37.0

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.


import 'package:config_builder_example/config.dart';
import 'package:config_builder_example/do_stuff_with_config.dart';

void main(){
  // run 'flutter packages pub run build_runner build' to generate the code
  final Config config = prodConfig;

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  config_builder: ^0.4.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:config_builder/config_builder.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/generators/config_generator.dart. (-0.50 points)

Analysis of lib/generators/config_generator.dart reported 1 hint:

line 85 col 29: 'name' is deprecated and shouldn't be used. Check element, or use getDisplayString().


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
analyzer ^0.39.2+1 0.39.4
build ^1.2.2 1.2.2
source_gen ^0.9.4+7 0.9.5
Transitive dependencies
_fe_analyzer_shared 1.0.3
args 1.6.0
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
logging 0.11.4
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+14
yaml 2.2.0