Reputation: 398
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:
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
Reputation: 17113
This practice is perfectly normal. The post that you linked to doesn't say not to create Stream
s inline. That is only applicable for Future
s and is made clear by the Flutter Docs in the FutureBuidler
class.
Upvotes: 1