Persist Bloc State in Flutter - Hydrated Bloc Tutorial
Vložit
- čas přidán 4. 09. 2019
- 📗 Learn from the written tutorial & get the project 👇👇
resocoder.com/hydrated-bloc-t...
👨💻 Do you write good code? Find out now!
resocoder.com/good-code-quiz
Users expect your apps to be easy and quick to use and they surely don't want to be slowed down by having to reenter some data every time they launch the app. Think about it - would you like it if the browser on your phone didn't remember the last website you opened?
That's why good apps persist their state to local storage. Sure, you can handle persistence in many ways, however, if you're using the flutter_bloc library, going the hydrated_bloc route is the best choice you can make.
Go to my website for more information, code examples, and articles:
● resocoder.com
Follow me on social media:
● / resocoder
● / resocoder
● / resocoder
Woow! I was dreaming of such a tutorial, and there it is. You are awesome! Thank you.
If anybody struggled with "flutter packages pub run build_runner build" do not forget to add "build_runner:" under dev_dependencies:
Thanks for your great explanations. I learned a lot from your videos and I come back to them often when I want to deepen my knowledge.
Great one bro ! We are still waiting for the part 4 of the Clean Architecture.
Cool video, my friend! Now the setup is a bit different than it was at the moment you made this video but in general very cool and it's not hard to read official usage documentation to understand how to do all the setup by yourself. Also this code generation with json_annotation and json_serialization was absolutely new to me and it's quite handy in conjunction with hydrated_bloc.
this was helpful
Hello! Can you do an update video for the hydrated_bloc versión 7.0.0 or higher? I really have a lot of difficulties right now about the update
Jsonserializable was something new for me!! Great videos !!
Turning the main method async a good approach? Will it delays the execution of runApp().
May i ask your thouhts about provider vs bloc?
What if a state returns List of the model class how to return the list when the return type is Map of both toJson and fromJson
Please update these wonderful videos, its great but it's not working at all now.
Its me again. My example is a shopping cart. My state(containing list of products added to the cart) are stored and restored with success after watching your tutorial, thanks for that. But everytime i add new products to the restored cart or remove a product from it. The cart empty itself. i mean the list of products in the cart which was restored by hydrated get empty. Do you know why? Can you help?
How you customized ubuntu ,tell about that
Great tutorial. Could you do this same tutorial using firebase and hydrated bloc?
Firestore and RealtimeDatabase implement their own local storage strategies with the great advantage that they sync the local data with the online servers automatically. So hydrated bloc is not really needed, you can use a regular Bloc and get your initial data directly through the Firestore SDK and let it handle the rest.
where are remaining TDD & CLEAN architecture videos?
Some of them unedited on my SSD, most of them in preparation.
coming from web-dev I don't understand why does keeping track of a single string value takes 8 files, 300 lines of code and 5 packages... also it does not seem linke something that would scale very well, as all those things would need to be duplicated for every single model.
True, but Flutter can handle this in just a few lines as well. It's all about the architecture around what you're trying to accomplish...
Hive just came as an update to hydrated_bloc -> can you make a video about it? Some changes to the code need to be done and a tutorial would be splendid.
I thought that hydrated_bloc uses Hive under the hood. I don't understand what you mean. Do you have some resource where I can read about it?
In the Dart language tour it recommends to not use the "part" keyword (dart.dev/guides/libraries/create-library-packages). Has something changed that I'm not aware of? Or is there an important reason for using this against the recommendations in the official documentation? Thanks!
The part keyword is necessary for the code generation to work. This way the generator can manage it's own files, and doesn't touch any files written by the developer. Lots of libs work that way.
If you see any plugin error, you have to add the following line of code in the main function
``WidgetsFlutterBinding.ensureInitialized();``
before the run app function
for more information visit this answer on stackoverflow : stackoverflow.com/questions/57689492/flutter-unhandled-exception-servicesbinding-defaultbinarymessenger-was-accesse
Thank you for the tip! One more thing, could you make a video how use @override transform: in the bloc
I am building a weather app based on your lessons and I found a way to debounce the input text:
@override
Stream transform(Stream events,
Stream Function(WeatherApiEvent event) next) {
return super.transform(
Observable(events).debounceTime(Duration(milliseconds: 500)).distinct(),
next);
}
It debounces but how do I filter the events I want to be debounced. Cheers m8. Thank you
I may create a tutorial on that, of course! In the mean time, you are probably using an older version of the bloc package, since the "transform" method no longer exists. Check out the release notes for version 0.15.
@@ResoCoder I'm using flutter_bloc: ^0.20.0 , meanwhile I found a solution: Stream transform(Stream events,
Stream Function(WeatherApiEvent event) next) {
return super.transform(
// Debounces all Events except ApiErrorEvent
Observable(events).debounce(
(window) => (window is ApiErrorEvent)
? window
: TimerStream(true, Duration(milliseconds: 500)),
),
next,
);
}
edit: I updated to flutter_bloc 0.21.x which uses bloc 0.15.x transformEvents instead of transform is just a matter of renaming . transformStates override was added though
please update the hydrated bloc package
i get this issue after following the tutorial "Converting object to an encodable object failed" can you help ?
nevermind i fixed it by passing "explicitToJson: true" parameter to @JsonSerializable() in my model