Why use InheritedWidget while we can use Broadcast Streams | StreamBuilder and Static Variables [closed]
Asked Answered
C

1

3

Why use InheritedWidget while we can use Broadcast Streams | StreamBuilder and Static Variables?

Why should we bother about redux, scoped model, etc. while we can have a simple and clean architecture?

enter image description here

Chintzy answered 21/4, 2018 at 17:12 Comment(0)
H
2

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.

Hypertrophy answered 21/4, 2018 at 18:16 Comment(11)
Thanks, I'm not looking for a replacement, I'm looking for a simple and clean architectureChintzy
when I'm using a StreamBuilder, I'm actually overriding the content for only a part of the screen, Am I wrong?Chintzy
You're wrong. InheritedWidget pass info to it's children. While stream is inside the widget. So in the case of InheritedWidget, other widgets can have influence. While with streams they can'tAeolus
The stream is not inside the widget, the stream is broadcast and is global to the application. there's no need to pass down anything down the hierarchy, just store the state in a global/static variableChintzy
But you share the same stream. While you instantiate multiple inheritedwidget. Just try to reproduce Theme with streams, you'll easily understandAeolus
I know what your'e talking about, changing the theme forces to redraw all the widgets, but subscribing every widget to a stream is a PITAChintzy
There's more to what Remi is saying (although Remi this might be a language thing for you, but saying "you're wrong" as the first thing in a sentence is generally a good way to make the person ignore the rest of what you're about to say and assume you're an ass.) You can have different parts of your application use different themes without having to set up different subscriptions simply by defining more than one theme - which is quite powerful. Also, in general any architecture that relies strongly on static variables is probably not optimal.Geniegenii
Especially once you start doing things like unit testing, promoting code re-use, and trying to follow clean code principles you'll realize how using static subscriptions makes things difficult. For a very small application it could save you time but in the long run it can produce harder to maintain code.Geniegenii
I don't think what you're talking about is in the scope of the question @rmtmckenzie. The question is "why use inheritedwidget over stream?" not "should I base my app around streams".Aeolus
But I personally think BLoC (aka stream everywhere) is a decent architecture.Aeolus
Could you please explain what is business logic and what is UI logic?Sheen

© 2022 - 2024 — McMap. All rights reserved.