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.

example/common_configs_example.dart

import 'package:common_configs/common_configs.dart';

/// Create your own config by extending [Config].
class Awesome extends Config {
  Awesome(this.id);
  @override
  final AwesomeType id;
}

/// Optionally use an enum as an identifier to differentiate between different [Config]s.
enum AwesomeType {
  good,
  better,
  best,
}

Awesome createGoodConfig() => Awesome(AwesomeType.good);
Awesome createBetterConfig() => Awesome(AwesomeType.better);
Awesome createBestConfig() => Awesome(AwesomeType.best);

class AwesomeMapConfig extends MapConfig<AwesomeType> {
  AwesomeMapConfig(super.id, super.data);
}

AwesomeMapConfig createMapConfig() => AwesomeMapConfig(
      AwesomeType.better,
      {'Hello': 'World'},
    );

void main() {
  print('== `default` config ==');

  /// Set your config with [Config.put].
  ///
  /// Example use case: Your different entrypoints can use different configs.
  Config.put(create: createGoodConfig);

  /// With [isA] method, you can check the current config.
  print('is good: ${Config.isA(AwesomeType.good)}');
  print('is better: ${Config.isA(AwesomeType.better)}');
  print('is best: ${Config.isA(AwesomeType.best)}');

  /// You can also use different names for getting or storing a config.
  const someOtherScopeName = 'awesome.map';

  print('== `$someOtherScopeName` config ==');

  Config.put(create: createMapConfig, name: someOtherScopeName);

  print('is good: ${Config.isA(AwesomeType.good, someOtherScopeName)}');
  print('is better: ${Config.isA(AwesomeType.better, someOtherScopeName)}');
  print('is best: ${Config.isA(AwesomeType.best, someOtherScopeName)}');
}
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