Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart Flatter dropdownlist填充速度太慢_Dart_Flutter - Fatal编程技术网

Dart Flatter dropdownlist填充速度太慢

Dart Flatter dropdownlist填充速度太慢,dart,flutter,Dart,Flutter,我有一个下拉列表,列表项是从webapi获取的。 有时获取json需要一段时间,dropdownlist无法成功绑定。将引发异常: I/flutter (21159): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (21159): The following assertion was thrown building S

我有一个下拉列表,列表项是从webapi获取的。 有时获取json需要一段时间,dropdownlist无法成功绑定。将引发异常:

I/flutter (21159): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (21159): The following assertion was thrown building ScopedModelDescendant<MainModel>(dirty):
I/flutter (21159): 'package:flutter/src/material/dropdown.dart': Failed assertion: line 481 pos 15: 'value == null ||
I/flutter (21159): items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not true.

然后正确填充dropdownlist,但当然没有选择任何元素。

可能
itemId
就像一个巨大的字符串,比较它需要很长时间?不,它是小于10000的整数
  Widget _buildDropDownList(MainModel model) {

      isEmpty: itemId == 0,
      child: new DropdownButtonHideUnderline(
        child: new DropdownButton<String>(
          value: itemId != 0 ? itemId .toString() : null,
          isDense: true,
          onChanged: (String newValue) {
            setState(() {
              itemId = model.allItems
                  .where((x) => x.itemId == int.parse(newValue))
                  .first
                  .itemId;
            });
          },
          items: model.allItems.map((Item item) {
            return new DropdownMenuItem<String>(
              value: item.itemId.toString(),
              child: new Text(item.itemName),
            );
          }).toList(),
        ),
      ),
    );
  }
value = null