Flutter: StreamBuilder uses old stream instead of new stream


Flutter: StreamBuilder uses old stream instead of new stream



I'm trying to show a Google-Firestore real-time list on my Flutter app using Flutter's StreamBuilder.



However, the stream seems to be using both the old data and the new data, instead of just the new one. (See below)


//This is the widget with the stream
Expanded(
child: StreamBuilder<QuerySnapshot>(
stream: _firestoreInstance.collection("seeks").document('145725').collection("classes").document(_chosenClass)
.collection("classTopics").document(date).collection("dateTopics").snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if (!snapshot.hasData) return Text('Loading...');
return ListView(
children: snapshot.data.documents.map((DocumentSnapshot document){
debugPrint("DOCCUMENT ID: ${document.documentID} AND topic Name ${document['topicName']}");
return ListTile(
title: Text(document['topicName']),
subtitle: TopicSlider(_chosenClass, document.documentID), //pass class name and topic id to slider to save in firebase
);
}).toList(),
);
},
),
)



1st I pick CS115 and the date which gets me the correct list (click for picture)



The document IDs are also correct (output of debugPrint):



However, as soon as I change the class to CS331, this happens.



As you can see, the first three document IDs for CS331 is exactly the same as the IDs for CS115. It seems as if the stream just uses whatever data was previously there before using the new data. I don't understand why that is since I call setState every time the dropDownItem is changed -- so that the whole widget can rebuild (thus regenerating a new stream object with the updated data). This causes the new UI to use the values of old data. I've been stuck on this problem for a couple days now and nothing seems to be working. Does anyone know how to solve this weird bug? Thanks in advance!





I've tried to reproduce your problem, but for me it works as expected. Could you post your complete main.dart?
– attdona
Jun 30 at 9:45





Hi, I think it was my fault. I was messing around with the build method. I found a workaround though. Instead of listing in real time, I just used a normal HTTP get request. Thanks for your help!
– Prince Hodonou
2 days ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV