Reputation: 73
in this code I am able to retrieve data from Firestore once after I starts to run this page. Is it possible to make it run in real time where it will be able to get all the data from Firestore in real time?
Future getMarker() async{
Firestore.instance.collection('markers').getDocuments().then((myData){
if(myData.documents.isNotEmpty){
for (int i = 0; i < myData.documents.length; i++){
initMarker(myData.documents[i].data, myData.documents[i].documentID);
}
}
});
}
When i change the getDocuments()
to snapshots()
then method then()
will give out an error stated that then()
is not a Stream type. Or is there any approach to this. Thank you in advance.
Upvotes: 0
Views: 100
Reputation: 83093
As explained in the doc, one option is to use the listen
method of the Stream
returned by the snapshots()
method.
The doc also shows an example with another option: using a StreamBuilder
which "helps automatically manage the streams state and disposal of the stream when it's no longer used within your app".
Upvotes: 3