fast_rx_persistence 0.2.0+1 icon indicating copy to clipboard operation
fast_rx_persistence: ^0.2.0+1 copied to clipboard

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 #

ClassUse-case
FastRxPersistenceInterfaceInterface for getting/setting values in the key/value store
FastRxPersistenceConverterUsed to convert a value to/from a persistence store
InlineConverterConvenience class to create a custom converter inline
EnumStringConverterConvenience class to convert an enum to/from string
EnumIntConverterConvenience class to convert an enum to/from int

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(),
      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>{};

  @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
140
pub points
29%
popularity

Publisher

verified publisher iconrexios.dev

An interface for implementing fast_rx key/value store persistence

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

Dependencies

fast_rx, flutter

More

Packages that depend on fast_rx_persistence