简体   繁体   English

如何根据 flutter 中的其他下拉菜单重置 DropdownSearch.multiSelection()?

[英]how to reset DropdownSearch.multiSelection() based on other dropdown in flutter?

how to reset DropdownSearch.multiSelection() based on other dropdown in flutter?如何根据 flutter 中的其他下拉菜单重置 DropdownSearch.multiSelection()?

in my app, i have to reset DropdownSearch.multiSelection() based on one another dropdown.在我的应用程序中,我必须根据另一个下拉菜单重置 DropdownSearch.multiSelection()。

Here is my Code for DropdownSearch.multiSelection().这是我的 DropdownSearch.multiSelection() 代码。

 DropdownSearch<ComplaintBook>.multiSelection(
                        items: dropDownComplaintBookModels,
                        popupProps: PopupPropsMultiSelection.modalBottomSheet(
                            showSearchBox: true,
                            searchFieldProps: TextFieldProps(
                              decoration: InputDecoration(
                                labelText: "Complaints*",
                                prefixIcon: Icon(Icons.restart_alt_outlined),
                              ),
                            )),
                        dropdownDecoratorProps: DropDownDecoratorProps(
                          dropdownSearchDecoration: InputDecoration(
                            border: OutlineInputBorder(),
                            prefixIcon: Icon(Icons.restart_alt_outlined),
                            labelText: "Complaints*",
                            // hintText: "Select an Int",
                          ),
                        ),
                        itemAsString: (ComplaintBook complaint) =>
                            complaint.tokenNumber!,
                        onChanged: (List<ComplaintBook>? complaint) {
                          selectedComplaintBooks = complaint!;
                        },
                        selectedItems: selectedComplaintBooks,
                        validator: (value) {
                          if (value!.isEmpty) {
                            return "Select atleast one Complaint !";
                          }
                          return null;
                        },
                      ),

and i have to reset above dropdown based on below dropdown.我必须根据下面的下拉菜单重置上面的下拉菜单。

DropdownSearch<Customer>(
                        items: dropDownCustomerModels,
                        popupProps: PopupProps.modalBottomSheet(
                            showSearchBox: true,
                            searchFieldProps: TextFieldProps(
                              decoration: InputDecoration(
                                labelText: "Customer*",
                                prefixIcon: Icon(Icons.person),
                              ),
                            )),
                        dropdownDecoratorProps: DropDownDecoratorProps(
                          dropdownSearchDecoration: InputDecoration(
                            border: OutlineInputBorder(),
                            prefixIcon: Icon(Icons.person),
                            labelText:
                                AppLocalizations.of(context).lblCustomer + "*",
                            // hintText: "Select an Int",
                          ),
                        ),
                        itemAsString: (Customer cust) => cust.companyName!,
                        onChanged: (Customer? customer) {
                          setState(() {
                            StateModel state = customer!.state!;
                            stateController.text = state.name ?? "-";
                            selectedComplaintBooks.clear();
                            setState(() {});
                            presenter.getComplaintBookList(customer.id!);
                            dropdownValueCustomer = customer;
                            print(customer.companyName);
                          });
                        },
                        validator: (value) {
                          if (value == null) {
                            return "Select Customer !";
                          }
                          return null;
                        },
                      ),

as code i clear the selectedComplaintBooks list but it still shows selected item in dropdownsearch.multiselaction as below image.作为代码,我清除了 selectedComplaintBooks 列表,但它仍然在 dropdownsearch.multiselaction 中显示所选项目,如下图所示。 在此处输入图像描述

so how I can reset the DropdownSearch.multiSelection() based on DropdownSearch()?那么如何根据 DropdownSearch() 重置 DropdownSearch.multiSelection()?

Please help me.请帮我。 Thank You.谢谢你。

I Solved this problem using GlobalKey.我使用 GlobalKey 解决了这个问题。

I just give a global key to DropdownSearch.multiSelection()我只是给 DropdownSearch.multiSelection() 一个全局键

as below.如下。

final dropDownKey = GlobalKey<DropdownSearchState<ComplaintBook>>();
 DropdownSearch<ComplaintBook>.multiSelection(
                        key: dropDownKey,
)

and reset it in DropdownSearch() onchnage Like.并在 DropdownSearch() onchnage Like 中重置它。

onChanged: (Customer? customer) {
                          setState(() {
                            selectedComplaintBooks = [];
                            dropDownKey.currentState!.clear();
                          });
                        },

and its Done.和它的完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 flutter 中创建自定义下拉搜索 - How to create custom dropdownsearch in flutter 如何在 flutter 中使用本地数据库填充 DropdownSearch flutter - How to populate DropdownSearch flutter with local database in flutter 如何在flutter中设置DropdownSearch Selected Item的样式 - how too style DropdownSearch Selected Item in flutter flutter中DropDownSearch去除边框的方法 - How to remove border from DropDownSearch in flutter Flutter DropDownSearch 值在将焦点更改为其他小部件时重置 - Flutter DropDownSearch value resets on changing focus to other widgets 如何重置 flutter 中的下拉按钮? - How to reset the dropdown button in flutter? 从下拉菜单到 flutter 中的下拉搜索 - from dropdownmenu to dropdownsearch in flutter 当其他下拉值在颤动中发生变化时,将下拉列表的值重置为偏移量 0 - Reset value of dropdown to offset 0 when other dropdown value changed in flutter Flutter 多选可搜索下拉列表,将所选项目作为芯片添加到字段 - Flutter multiselection searchable dropdown with selected item added to field as chip 我想更改出现在 DropdownSearch 中的项目的 TextStyle,它位于 flutter 中的 dropdown_search package 下 - I want to change the TextStyle of the items appear in DropdownSearch which comes under dropdown_search package in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM