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
73 stars 83 forks source link

use of itemBuilder #151

Closed colinbes closed 2 months ago

colinbes commented 2 months ago

Can you please explain how to use itemBuilder as there is no description of it's usage.

I assume by setting itemBuilder I can use my own ListTile to show my drop down choice in displayed MultiDropdown items list.

If I add my own itemBuilder void callback then it appears that I have to provide my own MultiSelectController - is this correct.

If above is correct then I would have to use onTap callback with itemBuilder and this is where I am totally lost as I am unable to add my own callback. Also not sure what concept was as item or at very least item's index would need to be provided to callback to know what item was clicked on.

I have tried:

    void itemTapped(DropdownItem<int> item) {
      _controller.addItem(item);
    }

and in MultiDropdown I have

itemBuilder: (DropdownItem<int> item, int index, () => itemTapped(item)) {
      return ListTile(
            leading: const Icon(Icons.ac_unit),
            title: Text(item.label),
            trailing: item.selected ? const Icon(Icons.check_circle) : const Icon(Icons.radio_button_unchecked),
       );
},

I suspect () => itemTapped(item) is not valid but don't see how one would pass item or index as onTap is defined as Function() with no parameters.

Once I get this working I am happy to assist with updating documentation

colinbes commented 2 months ago

Challenge was I was thinking that for onTap item I was providing the onTap function, whereas in itemBuilder: (DropdownItem<int> item, int index, onTap) {} the onTap is a callback that you call in your itemBuilder.