StreamBuilder (Flutter Widget of the Week)

Google for Developers · 333K views · 2018 · 1:40

Open on YouTube

Software (other)Web developmentexplainer

Why Stack Overflow recommends it

Stack Overflow users link it when answering Flutter questions about rebuilding the UI from a Stream, as a quick official introduction to StreamBuilder.

Recommended by 6 people across 6 different months, 2019 to 2022.

What it is

A 1m40s entry in Google's Flutter Widget of the Week series explaining StreamBuilder, the widget that rebuilds its children whenever a Dart stream emits new data. It covers giving it a stream and a builder, and is presented by the Flutter team on the Google for Developers channel.

What people said

Strong rec Evrard-Nil Daillet · 2019-07 · Stack Overflow · on “The getter 'bloc' called on null”

Well you are not checking that your stream contains data, you should check stream documentation. This video is great [this video] For further details, I recommend this article [LINK]

Recommends drogel · 2019-08 · Stack Overflow · on “How to have fade in and fade out between multi widgets”

I suspect that `StreamBuilder` is what you are looking for. You will need to change your connection states, that are probably built around `Future`, and re-build them around `Stream`, that will let you listen to changes on network data. `StreamBuilder` will let you react to changes in your `Stream` and update your UI based on them. Here is a Widget of the Week video [this video] about `StreamBuilder` that you might find useful. However, I recommend you mark this question as solved by my answer and open another question, so people will find the topic easily.

Recommends MαπμQμαπkγVπ.0 · 2020-05 · Stack Overflow · on “How do I access http request using Streams in Dart?”

How about consider using StreamBuilder [this video] , and Cloud Firestore [LINK] . And head to this tutorial [LINK] for an in depth discussion?

Recommends sidrao2006 · 2021-01 · Stack Overflow · on “How to update and rebuild specific class instance from (dart) Stream?”

Use StreamBuilder [LINK] ! Widget that builds itself based on the latest snapshot of interaction with a Stream. Widget rebuilding is scheduled by each interaction, using State.setState, but is otherwise decoupled from the timing of the stream. Check out this video on [this video] StreamBuilder( stream: , // some stream... builder: (BuildContext context, AsyncSnapshot<int> snapshot) { List<Widget> children; if (snapshot.hasError) { // Handle error } else { switch (snapshot.connectionState) { case ConnectionState.none: // Not currently connected to any asynchronous computation. break; case ConnectionState.waiting: // Connected to an asynchronous computation and awaiting interaction. break; case Con

Recommends Adithaz · 2021-03 · Stack Overflow · on “How to call setState() during integration tests?”

I think you don't need to use setState() in this case. Use StreamBuilder to show GridView based on data from firebase. Here's a video of how to implement it [this video]

Recommends pskink · 2021-10 · Stack Overflow · on “Text widget not updating inside StreamBuilder”

`StreamBuilder.stream` is a stream with your data, each time that `Stream` triggers new data it rebuilds `StreamBuilder` by calling `build` method - see one minute introduction here: [this video]

Cites ahmetakil · 2021-03 · Stack Overflow · on “Flutter - NoSuchMethodError: Class '_MapStream<QuerySnapshotPlatform, QuerySnapshot>' has no instance method 'then'”

Future getFriend(String ownerid) async { return await FirebaseFirestore.instance .collection("users") .doc(ownerid) .collection("friends") .get(); } .then() is used for futures so your getFriend() method needs to return a Future If you want to use the Stream than you need to use a StreamBuilder instead of calling a function in initState This might help: [this video]

Cites pskink · 2021-09 · Stack Overflow · on “Show progressIndicator in a Flutter app while scanning barcode”

[this video] - the method `getBarcodeStreamReceiver()` returns a `Stream` so use that `Stream` inside `StreamBuilder` widget

Cites dart-novice · 2022-05 · Stack Overflow · on “Dart StreamBuilder initial value”

To my understanding, StreamBuilder is taking 2 things as its arguments: the stream itself that will be listened to the builder : in here, we are going to define what we want to do when a new data comes from our stream. From a little bit googling and surfing in stackoverflow, I think my understanding is correct: builder is only getting triggered when a new data comes to the stream. I also heard from official video, it is good practice to provide initial data , or check hasData() and act accordingly. ( [this video] ) My question is, why? and how? If the StreamBuilder's build part is only getting triggered when there is a new event, how come it will get triggered in the beginning, when there are no

Cites Adrian Samoticha · 2022-08 · Stack Overflow · on “How to parse date 2022-08-04T16:13:51+03:00 correctly in Dart?”

var time = DateTime.parse(snapshot.data?.toString() ?? '').toLocal(); If snapshot.data is null, you are passing an empty string into DateTime.parse . To fix this, rather than replacing the empty string with a nonsensical (but parsable) value, you should be able to use snapshot.hasData() to check if the snapshot has any data and if it doesn't display a loading indicator of some sort [this video] .