Updating Items, not updating the dropdown.
Hi there, great plugin here! Basically, so thankful with this plugin. But I am facing an issue when I updating the items parameters.
First, I have a component called InputMultiselect that wrap this widget. Something like this
class InputMultiSelect<T extends Object> extends StatelessWidget {
const InputMultiSelect({
super.key,
this.items,
this.selectedItem,
this.onChange,
this.name,
});
final List<T>? items;
final List<T>? selectedItem;
final String? name;
final Function(List<T>? selected)? onChange;
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, 0, 12, 12),
child: SizedBox.fromSize(
size: Size.fromHeight(39),
child: MultiDropdown<T>(
items: items!
.map((item) => DropdownItem(
label: item.toString(),
value: item,
selected: selectedItem!.contains(item)))
.toList(),
onSelectionChange: (selected) => onChange!(selected),
searchEnabled: true,
),
),
);
}
}
Then I will use in it my form simply just like this:
InputMultiSelect(
name: "Some Input",
selectedItem: _categories,
items: _categoryOptions,
onChange: onCategoryChange,
),
The problem is whenever I update _categoryOptions using setState() the dropdown will not update the items. I already do a trace to look how the plugin works, so may be I can get a hot fix for my issue.
I debug widget.items on line 383 the items is updated.
But here on line 433, it's uses _dropdownController.items instead of widget.items
There I assume may be the reason why the dropdown it's not updating.
Any idea how to do a hot fix here? Or Am I missed something? Thanks!
@singgihmardianto please were you able to solve this issue?
class InputMultiSelect<T extends Object> extends StatefulWidget { const InputMultiSelect({ super.key, this.items, this.selectedItem, this.onChange, this.name, });
final List<T>? items; final List<T>? selectedItem; final String? name; final Function(List<T>? selected)? onChange;
@override State<InputMultiSelect> createState() => _InputMultiSelectState<T>(); }
class _InputMultiSelectState<T extends Object> extends State<InputMultiSelect<T>> { final MultiSelectController<T> controller = MultiSelectController();
@override void initState() { super.initState(); }
@override void didUpdateWidget(InputMultiSelect<T> oldWidget) { super.didUpdateWidget(oldWidget);
if (!listEquals(oldWidget.items, widget.items)) { controller.setItems(widget.items! .map((item) => DropdownItem( label: item.toString(), value: item, selected: widget.selectedItem!.contains(item))) .toList()); } }
@override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.fromLTRB(0, 0, 12, 12), child: SizedBox.fromSize( size: const Size.fromHeight(39), child: MultiDropdown<T>( controller: controller, items: widget.items! .map((item) => DropdownItem( label: item.toString(), value: item, selected: widget.selectedItem!.contains(item))) .toList(), onSelectionChange: (selected) => widget.onChange!(selected), searchEnabled: true, ), ), ); } }
On Tue, Nov 19, 2024 at 3:24 PM Kehinde Alabi @.***> wrote:
@singgihmardianto https://github.com/singgihmardianto please were you able to solve this issue?
— Reply to this email directly, view it on GitHub https://github.com/oi-narendra/multiselect-dropdown/issues/156#issuecomment-2484679541, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEF7OWXGNJTJ2OR465S2JN32BK4P3AVCNFSM6AAAAABOGPADMKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBUGY3TSNJUGE . You are receiving this because you are subscribed to this thread.Message ID: @.***>