我想制作显示这样的城市的DropdownButtonFormField:
final List<String> cities = ['London', 'New York', 'Paris', 'Shanghahai', 'Tokyo'];
String _currentCity;
DropdownButtonFormField(
value: _currentCity ?? ' ',
decoration: textInputDecoration,
items: cities.map((city) {
return DropdownMenuItem(
value: city,
child: Text('$city City '),
);
}).toList(),
onChanged: (val) => setState(() => _currentCity = val ),
),
并且如果我将列表中的字符串更改为数字,则效果很好:
final List<String> cities = ['0', '1', '2', '3', '4'];
尽管我使用字符串列表,但有人可以告诉我这是怎么回事
您可以尝试将_currentCity设置为默认值吗?