我有一个我希望在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(),
Run Code Online (Sandbox Code Playgroud)
这是我的项目清单:
List<String> _locations = ['A', 'B', 'C', 'D'];
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
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.
Run Code Online (Sandbox Code Playgroud)
我假设值为_selectedLocationnull.但我正在初始化它.
String _selectedLocation = 'Please choose a location';
我是扑扑发展的新手。我正在使用应用程序的下拉按钮。打开下拉菜单时,文本将在弹出对话框中被剪切。下面我附上了带有编码的屏幕截图。请指导我解决此问题。
DropdownButtonHideUnderline(
child: new DropdownButton(
isExpanded: true,
value: dropDownValue,
isDense: true,
//icon: Icon(Icons.keyboard_arrow_down, color: Colors.white,),
onChanged: (String newValue) {
setState(() {
dropDownValue = newValue;
state.didChange(newValue);
});
},
items: dropDownList.map((String value) {
return new DropdownMenuItem(
value: value,
child: new SizedBox(
width: MediaQuery.of(context).size.width / 1.4,
child: new Text(value,
softWrap: true,
style: TextStyle(color: Colors.white, fontSize: 18.0),),)
);
}).toList(),
),
),);
Run Code Online (Sandbox Code Playgroud)