BambinoUA
BambinoUA

Reputation: 7100

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?

Upvotes: 1

Views: 2508

Answers (1)

MαπμQμαπkγVπ.0
MαπμQμαπkγVπ.0

Reputation: 6729

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.

StreamProvider is a more complete solution than StreamBuilder:

  • StreamBuilder is a widget that comes with Flutter, and rebuilds itself every time the stream gets updated.
  • StreamProvider is a widget that comes with the Provider package, it was built using StreamBuilder, but combines this with InheritedWidget, 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.

Upvotes: 2

Related Questions