solid-software / hydrated Goto Github PK
View Code? Open in Web Editor NEW๐ฐ A BehaviorSubject for Flutter with automatic persist and hydrate.
Home Page: https://pub.dev/packages/hydrated
License: MIT License
๐ฐ A BehaviorSubject for Flutter with automatic persist and hydrate.
Home Page: https://pub.dev/packages/hydrated
License: MIT License
Rxdart 0.22.0 has been released. Is it possible to update the library to use that version ?
I no longer use hydrated
so I'd like to find someone to help keep it from bitrotting. Seems like a handful of people still use it.
I tried to use the package but requires rxdart 0.20. I don't think I have something that can benefit from 0.21 but would be ok to update the package to 0.21.
Thanks
As pointed out by @solid-vovabeloded:
Currently if we use HydratedSubject
with a primitive type, custom persist
and hydrate
callbacks won't be invoked, or used at all:
The idea is to change the check order in the above method to use the custom callbacks, if they were provided, and then fall back to standard handling.
Use cases:
sharedpreferences
on Android is not the most secure way to store data. Adding a generic interface should give the user freedom of choice when it comes to choosing the layer which does the actual key/value persistence.In general the idea is to abstract away from details on how we do persistence, and turn this package into a generic reactive extension for a keyed storage.
Right now I am using streambuilder to fetch user data to show it in drawer menu. Every time user see drawer screen future are taking time to interact with network call and render the data. Can I use hydrated package to store user data whenever he logins ?
thank you.
This plugin is breaking my code because of the Observable removal of 0.23.x.
The upgrade can be easily made with rxdart_codemod.
Thanks, in advance.
[VERBOSE-2:shell.cc(186)] Dart Error: Unhandled exception:
Invalid argument(s): The source must not be null
#0 int.parse (dart:core/runtime/libintegers_patch.dart:51:25)
#1 new AdvertisingService.<anonymous closure> (package:when_coin/services/advertising.dart:41:62)
#2 HydratedSubject._hydrateSubject (package:hydrated/hydrated.dart:140:18)
<asynchronous suspension>
#3 new HydratedSubject._ (package:hydrated/hydrated.dart:58:5)
#4 new HydratedSubject (package:hydrated/hydrated.dart:89:16)
#5 new AdvertisingService (package:when_coin/services/advertising.dart:39:30)
#6 main (package:when_coin/main.dart:5:16)
#7 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
#8 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I love this feature to persist the value on the Bloc.
However shared preferences dependency makes it Flutter only package (maybe it is fine for now).
In case of Bloc pattern, it should not know anything about Flutter, because we could use that Bloc on AngularDart for example. Probably Hummingbird will make AngularDart obsolete but not sure when that can happen.
I think this package can go to Dart-only and provide flutter (shared preference, etc.) overrides, also will give any other future storage mechanisms (Firebase for example).
Suggestion:
AbstractHydrate with methods to override:
Fetches from a storage by a key (current HydrateSubject
could override this with SharedPreferences use)
T fetch() {
}
Stores value (serializes if needed/supported) and current HydrateSubject
can override this with current implementation.
store(T val) {
}
This would allow to have the hydrate
package Dart only, and 'flutter_hydrate' (or other name) for example use SharedPreferences
. In future more "plugin" packages can be created to serialize or store to DB or store to file, even Firebase.
Just idea, see my https://pub.dartlang.org/packages/flutter_fimber and https://pub.dartlang.org/packages/fimber packages that follows that logic.
I do not know if it's an issue, but when I installed it, there was a compatibility error, because there is a new version shared_preferences, which was in my project previously
Hello, I'm a flutter newbee.
I'm storing a token using this and it's working like a charm. Now I would like to know how to store a list of houses.
I have a list of favorite houses in my bloc. Like this:
...
BehaviorSubject<List<House>> _favoritesController = BehaviorSubject<List<House>>(seedValue: <House>[]);
Stream<List<House>> get favorites => _favoritesController.stream;
...
Is it possible to persist this list?
Thank you.
Currently we do not persist any value that is null or is equal to the seedValue. The purpose is to block hydration from triggering a persist that would overwrite persisted data.
Instead, we can block , we would block hydration from triggering a persist. This way, we block HydratedSubject from overwriting persisted values with null/seedValue, but we also allow the developer to explicitly persist null/seedValue.
If you try to hydrate with a key that has has no value (null), HydratedSubject will attempt to pass this null value to the hydrate function. Currently the user can guard for null in the hydrate function but it would be better if the hydrate function was just not called if the value for the key is null, allowing HydratedSubject to use seedValue.
line 140 hydrated.dart
tldr:
HydratedSubject with serialized class
Key never been used before
shared_preferences
returns null
HydratedSubject passes null to hydrate mapping function instead of using seedValue
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.