繁体   English   中英

当数据为空时来自下拉列表 Flutter 中的 API 错误出现“类型'字符串'不是'索引'类型'int'的子类型”

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM