I need to populate a DropdownButton from a document in Firestore. I can retrieve the data. When I look into the snapshot.data I see 2 records which is what I expect to see. In the code below, everything works fine as long as I comment out the code snippet as you can see.
Container(
child: StreamBuilder(
//stream: _firestoreService.getAgency(),
stream: _db.collection('agency').snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Center(
child: CircularProgressIndicator(),
);
} else {
//var length = snapshot.data.docs.length;
//print('length: ' + length);
return new DropdownButton<String>(
hint: new Text("Select Agency"),
value: _currentAgency,
/* <<<< The code below is where I am having problems
//onChanged: changedDropDownState,
**items: snapshot.data.docs.map((Map map) {
return new DropdownMenuItem<String>(
value: map["name"].toString(),
child: new Text(
map["name"],
),
);
}).toList(),**
*/
);
}
;
}),
),
When I uncomment the code and run the app I get this error:
======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building StreamBuilder<QuerySnapshot>(dirty, state: _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot<QuerySnapshot>>#d9273):
type '(Map<dynamic, dynamic>) => DropdownMenuItem<String>' is not a subtype of type '(QueryDocumentSnapshot) => dynamic' of 'f'
What I want to accomplish is to populate the value: attribute with the document ID but I don't see it in snapshot.data. The other thing I want to do is populate child: attribute with some of the values from the snapshot.data.
How do I do this?