common_configs 0.1.0 copy "common_configs: ^0.1.0" to clipboard
common_configs: ^0.1.0 copied to clipboard

Common configs that can be shared as global configs in the application or with dart libraries.

Common configs #

A simple package which can be used as a global config in your app or you can share configs with your packages.

Features #

  • Use as a global configs across your app.
  • Share configs with packages.
  • Access config from anywhere.
  • Load configs from a Map with [Config.fromMap].

Getting started #

Add this package as a dependency

dart pub add common_configs

and import in your file by adding the below statement

import 'package:common_configs/common_configs.dart';

Usage #

A short example.

Use anything to use as an identifier for your config's type. In this example, I'm using an enum ConfigType.

enum ConfigType {
  devel,
  staging,
  prod,
}

We'll use a pre-existing MapConfig which can use Map<String, dynamic> as a Config with an identifier.

Config createDevelConfig() => MapConfig(ConfigType.devel, { 'hello': 'world' });

To create your own config, start by extending the [Config].

To use this config, set it by using [Config.put].

Config.put(create: createDevelConfig);

By default, configs are stored by the name default.

To use a another name, you can use the name parameter when getting or setting a config.

Config.put(create: createDevelConfig, name: 'app.config');

Additional information #

You can write your own code to obtain configuration details from a source like a json, or .env file.

For a longer example, check out the /example folder.

4
likes
140
points
25
downloads

Publisher

verified publishermagnificsoftware.com

Weekly Downloads

Common configs that can be shared as global configs in the application or with dart libraries.

Documentation

API reference

License

MIT (license)

More

Packages that depend on common_configs