GithubHelp home page GithubHelp logo

solid-software / hydrated Goto Github PK

View Code? Open in Web Editor NEW
115.0 115.0 18.0 1.16 MB

๐Ÿšฐ A BehaviorSubject for Flutter with automatic persist and hydrate.

Home Page: https://pub.dev/packages/hydrated

License: MIT License

Objective-C 0.06% Dart 93.61% Kotlin 0.64% Swift 0.63% Ruby 5.06%

hydrated's People

Contributors

cadooo avatar jacobaraujo7 avatar lukepighetti avatar mateusfccp avatar solid-software-hq avatar solid-yuriiprykhodko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hydrated's Issues

Transferring ownership

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.

Update to rxdart 0.21

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

Consider supporting a generic persistence interface

Use cases:

  1. Custom wrappers over SharedPreferences -- some projects abstract away from persistence, making this package a bad choice for them, since we only support stock SharedPreferences.
  2. Secure storage -- while iOS should be good to go, 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.

Can I use this for user profile storing whenever user login.

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.

The source must not be null

[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)

Abstract methods to store/load the object

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.

ver. shared_preferences

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

Question: How could I persist a list of a model

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.

Allow intentional setting of null and seedValue

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.

Passing null to hydrate property causes exception

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.