首页 > 解决方案 > 当我将 id 作为 DropdownMenuItem | 中的值访问时,可搜索的下拉搜索不起作用 扑

问题描述

我正在使用 searchable_dropdown: ^1.1.3 包来搜索下拉菜单中的元素,当我使用区(给出区名称)作为 DropdownMenuItem 中的值时,它可以正常工作。但问题是当用户选择区时,我希望该值作为 DistrictId。但是当我将 DistrictId 作为值时,搜索不起作用。下面是我的代码。

                              Center(
                                child: SearchableDropdown.single(
                                  isExpanded: true,
                                  value: selectedName,
                                  hint: "Select one",
                                  searchHint: "Select one",
                                  // hint: Text('Select Name'),
                                  items: districtList.map(
                                    (list) {
                                      return DropdownMenuItem(
                                        child: Text(list['district']),
                                        value: list['districtId'],
                                      );
                                    },
                                  ).toList(),
                                  onChanged: (value) {
                                    setState(() {
                                      selectedDistrict = value;
                                      print(selectedDistrict );
                                    });
                                  },
                                ),
                              ),

这是包https://pub.dev/packages/searchable_dropdown

标签: flutterdartsearchpackage

解决方案


推荐阅读