fast_rx_persistence 0.1.4 copy "fast_rx_persistence: ^0.1.4" to clipboard
fast_rx_persistence: ^0.1.4 copied to clipboard

outdated

An interface for implementing fast_rx key/value store persistence

An interface for implementing fast_rx key/value store persistence

pub package codecov checks popularity likes pub points

Features #

Class Use-case
FastRxPersistenceInterface Interface for getting/setting values in the key/value store

Usage #

A Shared Preferences implementation is provided by fast_rx_shared_preferences

Simply call .persist() on any Rx value to persist it to the key/value store

import 'package:fast_rx/fast_rx.dart';
import 'package:fast_rx_persistence/fast_rx_persistence.dart';

void example() {
  FastRxPersistence.init(Store());

  // Simple example of persistence
  // Here 0 is the default value. If a value exists in the store for the given
  // key, the given value will be replaced by the value in the store.
  final rx = 0.rx..persist('key');

  // Saves the value to the store and notifies listeners
  rx.value = 1;

  // An example of persistence with value transformation
  final rx2 = 0.rx
    // The type here is [String] since that is the type stored in the store
    ..persist<String>(
      'key',
      // The store can optionally be overridden on a per-value basis.
      // Otherwise the store passed into [FastRxPersistence.init] will be
      // used.
      store: Store(),
      decode: int.parse,
      encode: (value) => value.toString(),
    );

  // Saves the value to the store as a string
  rx2.value = 2;
}

class Store extends FastRxPersistenceInterface {
  final _store = <String, dynamic>{};

  @override
  Object? get(String key) => _store[key];

  @override
  void set(String key, Object? value) => _store[key] = value;
}

Additional information #

See fast_ui for more information

1
likes
0
pub points
26%
popularity

Publisher

verified publisherrexios.dev

An interface for implementing fast_rx key/value store persistence

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

fast_rx, flutter

More

Packages that depend on fast_rx_persistence