TransmissionsDev
TransmissionsDev

Reputation: 398

StreamBuilder with Cloud Firestore bad practice?

This StackOverflow answer (How to deal with unwanted widget build?) says that widgets should have no side effects in their build function, and that when using a StreamBuilder, you should not create a stream inline, but initialize in initState in a StatefulWidget.

However, the official cloud_firestore docs show this example: Photo

This example creates the stream in the build function.

Is this truly bad practice, and the Firestore team is just wrong here, or is Firestore doing something under the hood that I don't know about that makes this okay?

Upvotes: 1

Views: 211

Answers (1)

Christopher Moore
Christopher Moore

Reputation: 17113

This practice is perfectly normal. The post that you linked to doesn't say not to create Streams inline. That is only applicable for Futures and is made clear by the Flutter Docs in the FutureBuidler class.

Upvotes: 1

Related Questions