Skip to content

A companion package to `state_beacon` that makes it easy to manage key-value based settings.

License

Notifications You must be signed in to change notification settings

btrautmann/beacon_settings

Repository files navigation

Beacon Settings

pub package CI codecov

A light-weight companion package to state_beacon that provides a simple way to manage settings for a dart application.

Example usage

For more complex examples (and examples using Flutter), see the Cookbook.

void main() {
  // Create a new instance of `MySettings` with an in-memory storage.
  final settings = MySettings(InMemoryStorage());

  // Print the current value of `isAwesome`. Since the `defaultValue` is true,
  // this is `true` on first access.
  print(settings.isAwesome.value); // Prints `true`

  // Change the value. In this case, use `state_beacon`s built-in `toggle` method.
  settings.isAwesome.toggle();

  // Print the new value of `isAwesome`.
  print(settings.isAwesome.value); // Prints `false`
}

class MySettings extends Settings {
  MySettings(super.storage);

  late final isAwesome = setting(
    key: 'isAwesome',
    decode: boolDecoder(defaultValue: true),
    encode: boolEncoder(),
  ).value;
}

Features

  • Simple: Define a setting with a key, a decoder, and an encoder.
  • Type-safe: Decoders and encoders are type-safe.
  • Flexible: Use the built-in decoders and encoders or define your own.
  • Extensible: Define your own Storage implementation.
  • Testable: Use the built-in InMemoryStorage for testing.
  • Compatible: Plug & play with other Beacons (see derivedSetting) and storage implementations like SharedPreferences.

Installation

dart pub add beacon_settings

About

A companion package to `state_beacon` that makes it easy to manage key-value based settings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages