[英]when data empty come form API in dropdown Flutter Error come "type 'String' is not a subtype of type 'int' of 'index'"
String? selectLocation;
列表位置 = [];
DropdownButtonFormField( value: selectLocation, decoration: const InputDecoration(border: OutlineInputBorder(), hintText: 'Select Location', labelText: 'Select Location', ), items: location.map((list) { return DropdownMenuItem( value: list[ 'tlocid'].toString(), child: Text(list['tlocdsc'].toString()));
}).toList(),
onChanged: (value) {
setState(() {
selectLocation = value;
});
})
在我的情况下,您的代码不会编译,除非我添加DropdownButtonFormField<String>
并且如果我为它提供空而不存在错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.