A light-weight companion package to state_beacon that provides a simple way to manage settings for a dart application.
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;
}
- 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
Beacon
s (seederivedSetting
) and storage implementations likeSharedPreferences
.
dart pub add beacon_settings