Closed sabari7320 closed 1 month ago
1 st page: MultiLevelDropdown
hintText: 'Designation',
label:'Designation',
items: designationList, // Assuming skillSetList is a list of strings
selectedItem: reset_multidropdown ? [] : desList, // Reset selected items if reset flag is true
onChanged: (selectedItems) {
// designationController.text = selectedItems.isNotEmpty ? selectedItems.join(', ') : ''; // Update the controller with the selected items
setState(() {
desList = selectedItems;
reset_multidropdown=false;// Update the list of selected skills
});
print("DESLIST${desList}");
},
),
2:page:class MultiLevelDropdown
MultiLevelDropdown({ required this.hintText, required this.label, required this.items, required this.onChanged, this.selectedItem, });
@override
_MultiLevelDropdownState
class _MultiLevelDropdownState
@override void initState() { super.initState(); // Initialize selected items with the provided selected items or an empty list _selectedItems = widget.selectedItem ?? []; }
@override
Widget build(BuildContext context) {
return DropdownSearch
popupOnItemRemoved: (selectedItems, removedItem) {
print("REMOVED ITem");
print(removedItem);
},
dropdownSearchDecoration: InputDecoration(
labelStyle: TextStyle(fontSize: 15, color: Colors.grey),
labelText: widget.label,
hintText: widget.hintText,
hintStyle: TextStyle(fontSize: 15, color: Colors.grey),
contentPadding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10),
),
),
mode: Mode.MENU,
showSearchBox: false,
items: widget.items!,
itemAsString: (item) => item.toString(),
onChanged: (selectedItems) {
setState(() {
_selectedItems = selectedItems;
});
widget.onChanged!(_selectedItems);
},
popupItemBuilder: (context, item, isSelected) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Row(
children: [
SizedBox(width: 8),
Text(item.toString()),
],
),
);
},
dropdownBuilder: (context, selectedItem) {
return Row(
children: _selectedItems.map((item) {
return Row(
children: [
Text("${item.toString()}"),
SizedBox(width: 8),
if (_selectedItems.last != item) Text(", "),
],
);
}).toList(),
);
},
);
}
} my codes
I regret for asking this question because most of things already have in example (i think many doesn't get guidence like comments) that's why their raising repeated questions. ok fine i found solution problem of mine is:
steps:
1) paste this final _multiKey = GlobalKey<DropdownSearchState
I regret for asking this question because most of things already have in example (i think many doesn't get guidence like comments) that's why their raising repeated questions. ok fine i found solution problem of mine is: steps:
- paste this final _multiKey = GlobalKey
(); 2.) pass the multikey 3.)and _multiKey.currentState?.clear(); this would be help for who stuggling to remove all items in multiselection
It works 🙌
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context Add any other context about the problem here.