Skip to main content

Mixins

MementoMixin#

You can add, undo or redo a state using the Memento Pattern. This means that you can return to the previous state using the method undo() and also advance with the method redo().


class CounterStore extends StreamStore<Exception, int> with MementoMixin {}
...
store.undo();store.redo();

HydratedMixin#

A mixin which automatically persists and restores store state.

Step 1: Use in your store.#

class CounterStore extends StreamStore<Exception, CounterState> with HydratedMixin {}

Step 2: Add a Serializable contract in your State class.#

Only necessary if your state is not a primitive type, such as int.

class CounterState implements Serializable<CounterState> {    final int value;    CounterState(this.value);
    @override    Map<String, dynamic> toJson() => {'value': value};
    @override    CounterState fromJson(Map<String, dynamic> map) =>  CounterState(map['value']);} 

Step 3: Implements a HydratedDelegate or use hydrated_triple.#

Add the package hydrated_triple in pubspec`s project add set delegate:

void main() {
    setTripleHydratedDelegate(SharedPreferencesHydratedDelegate());
    runApp(AppWidget());}

NOTE: HydratedMixin.hasInitiated will be true when it`s ready.