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.

- 3,738
- 2
- 26
- 45

- 2,618
- 5
- 40
- 85
-
1"I'm purposely keeping the question open don't hate me for that," I guess nobody will hate you for that, it just makes the question off-topic on StackOverflow. – Günter Zöchbauer Dec 16 '18 at 15:29
-
I just think that posting some questionable code wont help to get what I'm trying to understand; almost a month ago I posted this code https://stackoverflow.com/questions/53498473/flutter-error-widget-cannot-build-because-is-already-in-the-process-of-buildin from then I rewrote it with BLoC pattern through StreamBuilder and lastly I'm trying to do the same with a Scoped Model. I can post it if you care, but my real question is: which way is the best to rewrite the state as less as possible, have better performance or is more safe to use, which one is overkill – Francesco Iapicca Dec 16 '18 at 15:39
-
Adding code won't help if the question is opinionated or too broad. StackOverflow is not the right place for every kind of question. – Günter Zöchbauer Dec 16 '18 at 15:42
-
@GünterZöchbauer I can settle with your personal opinion or experience: do you use any of these 'techinque', why and what made you chose it? – Francesco Iapicca Dec 16 '18 at 15:47
-
2I haven't tried BLoC or Scoped Model. I worked on a bigger project using Redux. `StreamBuilder` and `InheritedModel` are more general purpose. BLoC, ScopedModel and Redux are more architecture specific. You can probably combine Redux with BLoC or ScopedModel, but as said, I didn't have a closer look at these 2 yet. – Günter Zöchbauer Dec 16 '18 at 15:54
-
3I'd suggest asking that on Gitter/Slack/Reddit instead. StackOverflow isn't the place for this kind of question. – Rémi Rousselet Dec 16 '18 at 15:57
-
2I feel like it's a reasonable question if it's framed more as 'what is the strength of each one', rather than when to use. I do think it's a question that would help a lot of people who are relatively new to flutter. – Ian Dec 16 '18 at 17:14
-
Btw I'd also not be afraid to roll your own in the interim. I haven't used any of them, as I felt it was getting in the way of me quickly getting something working. I'm often rejigging things around, and simply used singletons and my own simple notifier system to setState on other widgets. When I'm happy with the structure of everything (and understand some of the patterns better), I'll likely redo it. I don't think this is the 'flutter' way though, so others may reject that idea, and I don't think should be an answer unless quite a few others do the same. – Ian Dec 17 '18 at 09:15
-
1I'd advise checking out https://github.com/brianegan/flutter_architecture_samples as it has the implementation of a simple app in various architectural patterns. You can then decide for yourself which is most interesting to you. – rmtmckenzie Dec 17 '18 at 22:52
-
This video https://www.youtube.com/watch?v=RS36gBEp8OI shows pros and cons of the different approaches. – tottomotto Mar 24 '19 at 10:24
-
[An overview of Vanilla, Scoped Model and BLoC](https://medium.com/flutter-community/flutter-app-architecture-101-vanilla-scoped-model-bloc-7eff7b2baf7e) – Pavel Apr 09 '19 at 20:41
-
[Comparison between setState, ScopedModel, BLoC and Redux](https://medium.com/flutter-community/let-me-help-you-to-understand-and-choose-a-state-management-solution-for-your-app-9ffeac834ee3) – Pavel Apr 09 '19 at 20:42
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.

- 3,738
- 2
- 26
- 45
-
Could you please explain what is `business logic` and what is `UI logic`? – Muhammad May 20 '20 at 18:15
-
1
-
thank you, this is my question: https://stackoverflow.com/questions/61927721/what-are-the-difference-between-business-logic-and-ui-logic – Muhammad May 21 '20 at 05:14