'Essential difference between using StreamBuilder and StreamProvider
Could please someone to explain what essential difference (cons/pros) between using of StreamBuilder widget and StreamProvider (provider package). Why and when I need to use StreamProvider?
P.S. Moreover why do I need so many other providers (like ListenableProvider, ChangeNotifierProvider etc)? What advantage they give except naming? I can use Provider constructor to create any kind of data to be provided, right?
Solution 1:[1]
Use StreamBuilder for a stream that you are sure you will only need at that same widget. Use StreamProvider if your app is growing, passing this stream data through your app widgets will get messy.
StreamProvideris a more complete solution thanStreamBuilder:
StreamBuilderis a widget that comes with Flutter, and rebuilds itself every time the stream gets updated.StreamProvideris a widget that comes with the Provider package, it was built usingStreamBuilder, but combines this withInheritedWidget, allowing you to pass information through the tree of widgets efficiently.
You can also read through this article "Making sense of all those Flutter Providers" to understand what each of the main Provider types are for and watch this video that explains an evolution from using using StreamBuilder to StreamProvider and their benefits.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MαπμQμαπkγVπ.0 |
