Widget singleDropdownSearch( //here index is not mandatory and only for the singleDropdownSearch in listview or any loop
context,
List<MenuItem> listMenu,
void Function(MenuItem?, [int?, dynamic]) callback,
selectedMenuItem,
refName,
mandatory,
readOnly,
[index, fieldState]
) {
return SizedBox(
width: MediaQuery.of(context).size.width,
child: DropdownButtonHideUnderline(
child: DropdownSearch<MenuItem>(
autoValidateMode: AutovalidateMode.onUserInteraction,
popupProps: PopupProps.dialog(
itemBuilder: (BuildContext context, MenuItem item, bool isSelected) {
// print(isSelected);
return Container(
// margin: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
// <--- top side
color: Colors.grey.shade300,
width: 1,
)),
// borderRadius: BorderRadius.circular(5),
color: Colors.white,
),
child: ListTile(
title: Text(item.name.toString()),
),
);
},
showSelectedItems: false,
showSearchBox: true,
searchFieldProps: TextFieldProps(
// controller: _userEditTextController,
decoration: InputDecoration(
hintText: "Search $refName",
border: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.grey, width: 2),
borderRadius: BorderRadius.circular(5),
),
prefixIcon: const IconButton(
icon: Icon(Icons.search),
onPressed: null,
),
),
),
// disabledItemFn: (String s) => s.startsWith('I'),
),
items: listMenu,
enabled: !readOnly && listMenu.isNotEmpty,
itemAsString: (MenuItem u) => u.name,
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
labelText: mandatory ? "$refName*" : refName,
hintText: "Select $refName",
border: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.grey, width: 1),
borderRadius: BorderRadius.circular(5),
),
),
),
onChanged: (value) {
index == null ? callback(value, null, fieldState) : callback(value, index, fieldState);
},
selectedItem: selectedMenuItem,
validator: (value) {
return value == null && mandatory ? "Please add $refName" : null;
},
),
),
);
}
My DropdownSearch
rebuilds my widget infinite times when I pass selectedItem(initial value) in it. How can I fix this?