你好,我需要从flutter中的firestore数据库中填写我的下拉列表,我总是收到这个错误
应该只有一个项目具有[DropdownButton]的值:。检测到零个或2个或多个[DropdownMenuItem]具有相同的值'package:flutter/src/material/dropload.dart':断言失败:行890位置15:'items=null|||items.isEmpty||value=null|| items.where((DropdownMenuSitem({return item.value=value;}(.length==1'
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('guests').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
currencyItems = [];
snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data = document.data()! as Map<String, dynamic>;
currencyItems.add(
DropdownMenuItem(
child: Text(
data["name"]
),
value: data["id"],
),
);
print(" dataaaaaaaaaaaaaaaaaaaaaaaaaa $data");
}).toList();
return DropdownButton(
items: currencyItems,
onTap:(){
print(currencyItems);
} ,
onChanged: (currencyValue) {
final snackBar = SnackBar(
content: Text(
'Selected Currency value is $currencyValue',
style: TextStyle(color: Color(0xff11b719)),
),
);
//Scaffold.of(context).showSnackBar(snackBar);
setState(() {
_value = currencyValue;
});
},
value: _value,
isExpanded: false,
hint: Text(
"Choose Currency Type",
style: TextStyle(color: Color(0xff11b719)),
),
);
},
),
问题是因为每个DropDownMenuItem
必须有一个唯一的值,但有多个值相同。
检查从消防仓库检索到的数据。
尝试使用
forEach
而不是map