作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个位置列表,我想在 Flutter 中实现为下拉列表。我对这门语言很陌生。这就是我所做的。
new DropdownButton(
value: _selectedLocation,
onChanged: (String newValue) {
setState(() {
_selectedLocation = newValue;
});
},
items: _locations.map((String location) {
return new DropdownMenuItem<String>(
child: new Text(location),
);
}).toList(),
这是我的元素 list :
List<String> _locations = ['A', 'B', 'C', 'D'];
我收到以下错误。
Another exception was thrown: 'package:flutter/src/material/dropdown.dart': Failed assertion: line 468 pos 15: 'value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not true.
我假设 _selectedLocation
的值变为空。但我是这样初始化的。
String _selectedLocation = '请选择位置';
最佳答案
试试这个
DropdownButton<String>(
items: <String>['A', 'B', 'C', 'D'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (_) {},
)
关于drop-down-menu - 如何在 flutter 中实现下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49273157/
我是一名优秀的程序员,十分优秀!