JsonPersist class
An annotation placed on Notifiers to indicated that they should be persisted using JSON.
For JsonPersist to work, all involved objects must either be primitive objects
such as int, String, bool, double, List, Map, or objects that
contain a fromJson/toJson
method pair.
Notifiers should then call NotifierPersistX.persist in their build
method,
and pass a compatible Storage.
@riverpod
@JsonPersist()
class MyNotifier extends _$MyNotifier {
@override
SomeState build() {
persist(
// A storage that supports JSON-based persistence.
storage: ref.watch(storageProvider),
);
}
}
class SomeState {
const SomeState(this.count);
SomeState.fromJson(Map<String, Object?> json)
: count = json['count'] as int;
final int count;
Map<String, Object?> toJson() => { 'count': count };
}
- Implemented types
Constructors
- JsonPersist.new()
-
An annotation placed on Notifiers to indicated that they should be persisted
using JSON.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited