flutterblocstream-builderinherited-widgetscoped-model

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.


Solution

  • 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.