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

Can't remove an item with using chipDisplay. #201

Open
SittiphanSittisak opened this issue Jan 15, 2024 · 0 comments
Open

Can't remove an item with using chipDisplay. #201

SittiphanSittisak opened this issue Jan 15, 2024 · 0 comments

Comments

@SittiphanSittisak
Copy link

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.

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

1 participant