Skip to content

The same value is selected multiple times with setState() #11

Open
@hsynpsdmr

Description

@hsynpsdmr

When the page is loaded for the first time, I bring some values selected, as soon as I call setState() anywhere, the selected values are selected as many times as I use setState()

    MultiSelectContainer<String>(
      itemsDecoration: MultiSelectDecorations(
        decoration: BoxDecoration(color: Colors.grey[100], border: Border.all(color: Colors.grey[100]!), borderRadius: BorderRadius.circular(20)),
      ),
      suffix: MultiSelectSuffix(
        selectedSuffix: const Padding(
          padding: EdgeInsets.only(left: 5),
          child: Icon(
            Icons.check,
            color: Colors.white,
            size: 14,
          ),
        ),
      ),
      itemsPadding: const EdgeInsets.all(5),
      items: getStatusItem(),
      onChange: (allSelectedItems, selectedItem) {
        _selectedStatus.clear();
        _selectedStatus = allSelectedItems;
      },
    );
 List<MultiSelectCard<String>> getStatusItem() {
    List<MultiSelectCard<String>> items = [];
    for (var stt in status) {
      items.add(MultiSelectCard(value: stt, label: stt, selected: _selectedStatus.any((element) => stt == element)));
    }
    return items;
  }

The code I used on the page is above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions