multi_select_flutter icon indicating copy to clipboard operation
multi_select_flutter copied to clipboard

Can't remove an item with using chipDisplay.

Open SittiphanSittisak opened this issue 2 years ago • 0 comments

You can test by this code below.

class Test extends StatefulWidget {
  const Test({super.key});

  @override
  State<Test> createState() => _TestState();
}

class _TestState extends State<Test> {
  final items = [1, 2, 3, 4, 5].map((e) => MultiSelectItem(e, '$e')).toList();
  List<int> selectedItems = [];

  @override
  Widget build(BuildContext context) {
    final policeStationSelectedWidget = MultiSelectChipDisplay(
      icon: const Icon(Icons.cancel),
      items: items, // I tried `selectedItems.map((e) => MultiSelectItem(e, '$e')).toList()` and <MultiSelectItem<int>>[] but it doesn't work.
      onTap: (v) {
        selectedItems.removeWhere((element) => element == v);
        setState(() {});
      },
    );

    print(selectedItems);
    return MultiSelectDialogField(
      initialValue: selectedItems,
      items: items,
      chipDisplay: policeStationSelectedWidget,
      onConfirm: (v) {
        selectedItems = v;
        setState(() {});
      },
      searchable: true,
    );
  }
}

Nothing happened after I selected items and clicked remove at the icon of the policeStationSelectedWidget.

SittiphanSittisak avatar Jan 15 '24 17:01 SittiphanSittisak