如何处理列表-5000 DropdownMenuItem?

时间:2019-12-26 14:24:05

标签: flutter dart

我有带有字符串的列表-大约5k个位置。我需要将此列表转换为List ,并在SearchableDropdown中使用它。

如何最有效地做到这一点?还是当我启动应用程序并将其保存到某处时如何执行一次?

现在,每次打开一个屏幕时,每次加载时,我都有大约3-5秒的延迟。而且我不能使用其他SearchableDropdown,因为加载此大列表时存在滞后:/

  @override
  void initState() {
convert(BIG_LIST).then((value){
      list.addAll(value);
    });
}


Future<List<DropdownMenuItem>> convert(List<String> BIG_LIST) async {
    List<DropdownMenuItem> results = [];
    await Future.forEach(BIG_LIST, (string){
      results(DropdownMenuItem(
        child: Text(string),
        value: string,
      ));
    });
    return results;
  }


Container(
                      width: MediaQuery.of(context).size.width*0.6,
                      child: SearchableDropdown(
                        items: list,
                        isExpanded: true,
                        value: value,
                        hint: new Text('Select'),
                        searchHint: new Text(
                          'Select',
                          style: new TextStyle(fontSize: 24),
                        ),
                        onChanged: (value) {
                          print(value);
                          setState(() {
                            text = value;
                          });
                        },
                      ),
                    ),

0 个答案:

没有答案