Want to use TextField inside a Streambuilder in flutter? In order to use a StreamBuilder correctly you must ensure that the stream you are using is cached on a State object. While StreamBuilder can correctly handle getting new events from a stream, receiving an entirely new Stream will force it to completely rebuild. In your case, getClientProfile().snapshots() will create an entirely new Stream when it is called, destroying all of the state of your text fields.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Example extends StatefulWidget { @override State createState() => new ExampleState(); } class ExampleState extends State<Example> { Stream<SomeType> _stream; @override void initState() { // Only create the stream once _stream = _firestore.collection(collection).document(id); super.initState(); } @override Widget build(BuildContext context) { return new StreamBuilder( stream: _stream, builder: (context, snapshot) { ... }, ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.