embedded_config_annotations 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

embedded_config_annotations #

This package contains annotations for configuring code generation for the embedded_config package.

The embedded_config package allows application configurations to be embedded directly into source code at build-time. Please see its README for more information.

v0.1.1 #

  • Add an example to address package scoring.

v0.1.0 #

  • Replace @FromEmbeddedConfig annotation with @EmbeddedConfig.


This example showcases how to make use of the embedded config annotations to represent a multi-level config file.

Assuming the config file is the following and is located at lib/app_config.json:

    "apiUrl": "/api",
    "auth": {
        "clientId": "abcd1234",
        "policies": {
          "loginSignUp": "POLICY_LOGIN_SIGN_UP",
          "passwordReset": "POLICY_PASSWORD_RESET"

The previous file can be represented in code using the following classes:

// file: lib/app_config.dart

import 'package:embedded_config_annotations/embedded_config_annotations.dart';

part 'app_config.embedded.dart';

// Create a class for the top-level of the config file.
// The string given to the annotation is a key which allows the
// application's build.yaml file to map various config sources
// to this class. In this case, we choose `app_config` as the key.
abstract class AppConfig {
  // An example of one way to expose the generated class which
  // contains the embedded config values.
  static const AppConfig instance = _$AppConfigEmbedded();

  String get apiUrl;

  // Here we can reference another embedded config class as
  // a getter to provide a nicer interface for code utilizing
  // this top-level class.
  // The name of this getter does not matter, as the source
  // of the config values given to the AppAuthConfig class
  // is determined by its annotation.
  AppAuthConfig get auth;

  // Embedded config classes must declare a default
  // const constructor.
  const AppConfig();

// Create a class for the 'auth'-level of the config file.
// By utilizing the path property, the class can specify where
// in the config source that values should be read from. The path
// is a `.` separated list of config keys.
// The key for the build.yaml to use is also kept the same since
// this class is for the same sources as the AppConfig class.
@EmbeddedConfig('app_config', path: 'auth')
abstract class AppAuthConfig {
  String get clientId;
  AppPoliciesConfig get policies;

  const AppAuthConfig();

// Create a class for the 'policies'-level of the config file.
// Here we can see how that `.` separated syntax works. The
// policy configuration is inside of the `auth` object in the
// config, so we specify a path into it first.
@EmbeddedConfig('app_config', path: 'auth.policies')
abstract class AppPoliciesConfig {
  String get loginSignUp;
  String get passwordReset;

  const AppPoliciesConfig();

After this, the app_config key which each of the classes used can be mapped to the JSON configuration document inside of build.yaml:

          app_config: 'lib/app_config.json'

Use this package as a library

1. Depend on it

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

  embedded_config_annotations: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:embedded_config_annotations/embedded_config_annotations.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 Jan 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/embedded_config_annotations.dart.

Run dartfmt to format lib/embedded_config_annotations.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
pedantic 1.8.0