persist and hydrate
hydrated provides a behaviorsubject that automatically persists to flutter’s local storage and hydrates on creation!
easy to consume
all values are persisted with shared_preferences
and restored with automatic hydration.
final count$ = hydratedsubject<int>("count", seedvalue: 0);
/// count$ will automagically be hydrated with 42 next time it is created
count$.add(42);
ready for bloc
class hydratedbloc {
final _count$ = hydratedsubject<int>("count", seedvalue: 0);
valueobservable<int> get count$ => _count$.stream;
sink<int> get setcount => _count$.sink;
dispose() {
_count$.close();
}
}
supports simple types and serialized classes
we support all shared_preferences
types.
int
double
bool
string
list<string>
final count$ = hydratedsubject<int>("count");
we also support serialized classes with hydrate
and persist
arguments.
final user$ = hydratedsubject<user>(
"user",
hydrate: (string s) => user.fromjson(s),
persist: (user user) => user.tojson(),
);
reliable
hydrated is mock tested with all supported types and is dogfooded by its creator.
demo
Comments are closed.