我尝试在dropdownbutton中显示类别数据,当我选择category时,我得到这个错误,
items == null || items.isEmpty || value == null ||代码DropDownButton
class _DropDownButtonState extends State<DropDownButton> {
final CollectionReference categoryData = Firestore.instance
.collection('category')
.document('house')
.collection('subCategory');
Stream<List<Categories>> categories;
Categories _currentCategory;
@override
void initState() {
categories = categoriesData;
super.initState();
}
@override
Widget build(BuildContext context) {
return StreamBuilder<List<Categories>>(
stream: categories,
builder: ((context, snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
return DropdownButton(
hint: Text('choose category'),
value: _currentCategory,
items: snapshot.data
.map((doc) => DropdownMenuItem(
child: Text(doc.categoryname),
value: doc,
))
.toList(),
onChanged: (doc) => setState(() {
_currentCategory = doc;
print(_currentCategory.categoryname);
}),
);
}));
}
Future createHouseCategory(_categorynameController) async {
var id = Uuid();
String categoryId = id.v1();
await categoryData
.document(categoryId)
.setData({'categoryname': _categorynameController});
}
List<Categories> _categoriesDataFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc) {
return Categories(
categoryname: doc.data['categoryname'],
);
}).toList();
}
Stream<List<Categories>> get categoriesData {
return categoryData.snapshots().map(_categoriesDataFromSnapshot);
}
}发布于 2020-02-24 18:20:54
只要看看这个链接,我已经解决了下拉列表的问题:
可能您没有为value Field提供所需的参数,这就是为什么它不能在下拉按钮中显示索引的原因。如果它起作用了,请告诉我。
如果您有任何问题,请给我JSON示例,也许我们可以解决它
https://stackoverflow.com/questions/60372502
复制相似问题