I am trying to build a list from documents i have in Firestore. below is my Future function:
Future getBuyerList() async {
await Firestore.instance.collection('Deals').where('buyer_id',isEqualTo: uid_global).snapshots().listen((data) {
data.documents.forEach((doc) {
print('in function - ${doc["car"]}');
print(doc.data);
});
});
}
The above runs fine in the debugger. it shows the full list of items i am expecting to put into the List.
My Future Builder in my widget tree is as follows:
FutureBuilder(
future: getBuyerList(),
builder: (BuildContext context, snapshot) {
if(snapshot.hasData){
if(snapshot.connectionState == ConnectionState.waiting){
return Center(
child: CircularProgressIndicator(),
);
}else{
Center(
child: Text('data loaded')
);
}
}else if (snapshot.hasError){
Text('no data');
}
},
),
I have not yet loaded the snapshot into the Listview as i am trying to get the FutureBuilder to atleast run successfully. but i keep getting a FutureBuilder null error.
I tried running the function as a non void function as well by returning a list but then i get an error on compile saying i cannot assign a Map to Future>.
Please help.
@Peter Haddad's answer was correct but i also needed to make a change to the builder by adding AsyncSnapshot<QuerySnapshot>
:
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot)