config_builder 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

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):

dev_dependencies:
  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

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

  const Config({this.name, 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:

main.dev.dart:

import 'config.dart';

void main() => printConfig(devConfig);

main.test.dart:

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.2.0]

Use analyizer ^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.

example/lib/main.dart

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;
  printConfig(config);
}

Use this package as a library

1. Depend on it

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


dependencies:
  config_builder: ^0.2.0

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
2
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: other

Primary library: package:config_builder/config_builder.dart with components: io, build, mirrors.

Health suggestions

Format lib/annotations/config.dart.

Run dartfmt to format lib/annotations/config.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer ^0.36.4 0.36.4 0.38.5
build ^1.1.6 1.2.0
source_gen ^0.9.4+4 0.9.4+4 0.9.4+5
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.2.9 1.3.1
front_end 0.1.19 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.19 0.3.27
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0