hydrated 1.1.0
hydrated: ^1.1.0 copied to clipboard
An automatically persisted BehaviorSubject with simple hydration for Flutter. Intended for use with the BLoC pattern.
Hydrated #
Hydrated provides a BehaviorSubject that automatically persists to Flutter's local storage. An async hydrate()
method rehydrates on command!
Easy to consume #
All values are persisted with shared_preferences
and restored with hydrate()
at next app launch.
final count$ = HydratedSubject<int>("count", seedValue: 0); // persist
await count$.hydrate(); // hydrate
count$.add(42); // this value will be available on next app launch
Ready for BLoC #
class _Bloc {
/// persist
final count$ = HydratedSubject<int>("count", seedValue: 0);
_Bloc() {
/// hydrate
this.count$.hydrate();
}
// ...
}
Supports types and 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.
