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