解决方案: flutter要求DropdownButton中的value值与List<String> items中的值有重合
换句话说,让你的value有一个固定的初始值,这里用图举例
附上官方代码(可以直接copy):
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
String dropdownValue = 'One';
@override
Widget build(BuildContext context) {
return DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_downward),
elevation: 16,
style: const Tex