这是我目前为DropdownButton使用的代码:
new StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("Teams").snapshots(),
builder: (context, snapshot){
var length = snapshot.data.documents.length;
DocumentSnapshot ds = snapshot.data.documents[length];
return new DropdownButton(
items: <DropdownMenuItem>[
new DropdownMenuItem(child: new Text(""))
],
onChanged: _chooseTeam,
hint: new Text("Join a Team"),
value: team
);
}
),
我不知道如何将集合动态添加到DropDownButtonItems列表中。我该怎么办?
答案 0 :(得分:1)
items
参数采用List<DropdownMenuItem>
,这也意味着您可以映射List<DocumentSnapshot>
。
return DropdownButton(
items: snapshot.data.documents.map((DocumentSnapshot document) {
// I do not know what fields you want to access, thus I am fetching "field"
return DropdownMenuItem(child: Text(document.documentID)}),
)
答案 1 :(得分:0)
我明白了
new StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("Teams").snapshots(),
builder: (context, snapshot){
var length = snapshot.data.documents.length;
DocumentSnapshot ds = snapshot.data.documents[length - 1];
return new DropdownButton(
items: snapshot.data.documents.map((DocumentSnapshot document) {
return DropdownMenuItem(child: new Text(document.documentID));
}).toList(),
onChanged: _chooseTeam,
hint: new Text("Join a Team"),
value: team
);
}
),
我必须将长度设置为-1,并获得文档ID作为文本。我还不得不在地图上调用toList()
答案 2 :(得分:0)
npm install -g https://github.com/Me/my_module
该示例有望对您有所帮助