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

1

19

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.

Paradies answered 16/12, 2018 at 15:26 Comment(12)
"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.Golter
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 #53498973 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 overkillParadies
Adding code won't help if the question is opinionated or too broad. StackOverflow is not the right place for every kind of question.Golter
@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?Paradies
I 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.Golter
I'd suggest asking that on Gitter/Slack/Reddit instead. StackOverflow isn't the place for this kind of question.Generosity
I 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.Swung
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.Swung
I'd advise checking out 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.Akerley
This video youtube.com/watch?v=RS36gBEp8OI shows pros and cons of the different approaches.Conjoined
An overview of Vanilla, Scoped Model and BLoCBetimes
Comparison between setState, ScopedModel, BLoC and ReduxBetimes
B
3

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://mcmap.net/q/668518/-why-use-inheritedwidget-while-we-can-use-broadcast-streams-streambuilder-and-static-variables-closed

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.

Bifilar answered 19/4, 2019 at 6:4 Comment(3)
Could you please explain what is business logic and what is UI logic?Belorussia
You can make a new post a new question for thisBifilar
thank you, this is my question: #61928221Belorussia

© 2022 - 2024 — McMap. All rights reserved.