An interface for implementing fast_rx key/value store persistence

pub package codecov checks popularity likes pub points


Class Use-case
FastRxPersistenceInterface Interface for getting/setting values in the key/value store
FastRxPersistenceConverter Used to convert a value to/from a persistence store
InlineConverter Convenience class to create a custom converter inline
EnumStringConverter Convenience class to convert an enum to/from string
EnumIntConverter Convenience class to convert an enum to/from int


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() {

  // 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
      // The store can optionally be overridden on a per-value basis.
      // Otherwise the store passed into [FastRxPersistence.init] will be
      // used.
      store: Store(),
      converter: InlineConverter(
        fromStore: int.parse,
        toStore: (value) => value.toString(),

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

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

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

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

Additional information

See fast_ui for more information