I'm having a problem regarding dropdown menus and firestore, how can I bind a list of documents retrieved from firestore to a DropdownButton? Currently I'm having this error:
The argument type '(Map<dynamic, dynamic>) → DropdownMenuItem<String>' can't be assigned to the parameter type '(DocumentSnapshot) → dynamic'.
Code from my widget .dart:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class MessageList extends StatelessWidget {
MessageList({this.firestore});
final Firestore firestore;
var _mySelection;
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: firestore.collection('preciso-modelos').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
return new DropdownButton<String>(
isDense: true,
hint: new Text("Select"),
value: _mySelection,
onChanged: (String newValue) {
print (_mySelection);
},
items: snapshot.data.documents.map((Map map) {
return new DropdownMenuItem<String>(
value: map["id"].toString(),
child: new Text(
map["name"],
),
);
}).toList(),
);},
);
}
}
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…