oi-narendra / multiselect-dropdown

Streamlined Flutter widget for versatile multi-selection with extensive customization.
https://pub.dev/packages/multi_dropdown
GNU General Public License v3.0
74 stars 84 forks source link

Initialize selected items onInit (setSelectedOptions) #121

Closed mrizkynurfajrie closed 3 months ago

mrizkynurfajrie commented 3 months ago

Hi, Congratulations for your excellent works after release new stable version of this package a few days ago.

I little bit confused with this update. Before this update (on 2.1.4 ver.) to initiate selected items/options we can use .setSelectedOptions on controller. But in this update i can't see that function anymore. I can't find migration documentation for this feature/function. Is it replaced with new parameter just like setOptions to setItems, or you just remove it?

zhiyuanFan commented 3 months ago

you can init your items with selected attribute, like DropdownItem(label: value: selected:true)

mrizkynurfajrie commented 3 months ago

you can init your items with selected attribute, like DropdownItem(label: value: selected:true)

Oh okay, i got it. Thank you mate

singgihmardianto commented 2 months ago

Hi there,

I found that mutating the parameter selected is not mutating the view respectfully.

Let's say I have this: options = ['Foo', 'Bar'] selected = ['Foo']

then with a button I reset the selected so the value become [], the code run ok, no error, but the field is not cleared.

The full snippet here:

  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(),
        )
      )
    );

Am I missed something? Thanks!