I think I have now at least a vague idea of how to use a BLoC, Stream Builder and Inherited Widget(or Model) in my app (nothing special, but for me it took time), but playing with the Scoped Model
I had a sort of existential crisis: I feel they can mostly do the same thing or at least I can achieve the same apparent results with any of them, but I don't have the competence to understand when and why one is better than another.
Bloc is a good pattern that will be suitable for almost all types of apps. It helps improve the code's quality and makes handling states in the app much more manageable. It might be challenging for someone who is just beginning to use Flutter because it uses advanced techniques like Stream and Reactive Programming.
The BLoC pattern relies on: StreamController. A StreamController exposes a StreamSink to inject data in the Stream and a Stream to listen to data, flowing inside the Stream. StreamBuilder. A StreamBuilder is a Widget which listens to a stream and rebuilds when new data is emitted by the Stream.
Flutter bloc it's a great option, as you can see it's not complicated to use it and it's easy to understand the main concept of how can you use it. Also, It gives you a lot of ways to manage your views or widgets.
A set of utilities that allow you to easily pass a data Model from a parent Widget down to its descendants. In addition, it also rebuilds all of the children that use the model when the model is updated.
In short: If you have small apps use scoped models since bloc tends to complicate it, and if you have big app use bloc.
See this article for detailed explanation: bloc vs scoped_model
Here is a nice comparison between stream builder and inherited widget given by Remi Rousselet: https://stackoverflow.com/a/49958864/10471480
Streams/Sink definitely are excellent to store a state. There are some existing architectures, such as BLoC which uses them a lot.
But, Streams don't entirely replace InheritedWidget
either. InheritedWidget
comes with the cool ability to override it's content for only a part of the screen. One cool application of this is Theme
.
Generally speaking, Streams
are cool to store business logic. But when you need to store UI logic, InheritedWidgets
takes the upper hand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With