Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scoped Model, BLoC pattern, StreamBuilder and Inherited Widget(or Model) which one should I chose and why?

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.

like image 786
Francesco Iapicca Avatar asked Dec 16 '18 15:12

Francesco Iapicca


People also ask

Is BLoC necessary Flutter?

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.

What is Scopedmodel BLoC pattern in Flutter?

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.

Is Flutter BLoC Good?

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.

What is a scoped model?

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.


1 Answers

Scoped Models vs Bloc

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


Stream Builder vs Inherited Widget

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.

like image 163
Mangaldeep Pannu Avatar answered Oct 22 '22 07:10

Mangaldeep Pannu