Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Items, not updating the dropdown. #156

Open
singgihmardianto opened this issue Sep 14, 2024 · 2 comments
Open

Updating Items, not updating the dropdown. #156

singgihmardianto opened this issue Sep 14, 2024 · 2 comments

Comments

@singgihmardianto
Copy link

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.
image

But here on line 433, it's uses _dropdownController.items instead of widget.items
image

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!

@papakay
Copy link

papakay commented Nov 19, 2024

@singgihmardianto please were you able to solve this issue?

@oi-narendra
Copy link
Owner

oi-narendra commented Nov 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants