Closed JaviBonilla closed 4 months ago
Changing selectedOptions in the onItemDelete does not update the widget.
Example:
import 'package:flutter/material.dart'; import 'package:multi_dropdown/multiselect_dropdown.dart'; import 'package:multi_dropdown/widgets/selection_chip.dart'; void main() { runApp(const MainApp()); } const numOptions = 5; class MainApp extends StatefulWidget { const MainApp({super.key}); @override State<MainApp> createState() => _MainAppState(); } class _MainAppState extends State<MainApp> { final List<int> selected = []; ValueItem<int> valueItem(int value) => ValueItem(label: 'Item $value', value: value); @override Widget build(BuildContext context) { print('selected: $selected'); return MaterialApp( home: Scaffold( body: Padding( padding: const EdgeInsets.all(50), child: MultiSelectDropDown<int>( selectedOptions: selected.map((value) => valueItem(value)).toList(), onOptionSelected: (List<ValueItem<int>> selectedList) { setState(() { selected.clear(); selected.addAll(selectedList.map((e) => e.value ?? 0).toList()); }); }, options: <ValueItem<int>>[ for (int i = 1; i <= numOptions; i++) valueItem(i), ], selectedItemBuilder: (context, item) { return SelectionChip( chipConfig: const ChipConfig( backgroundColor: Colors.purple, labelColor: Colors.white, ), item: item, onItemDelete: (item) { setState(() { selected.remove(item.value); }); }, ); }, )), )); } }
https://github.com/oi-narendra/multiselect-dropdown/assets/20316179/47fa7d81-12a4-452e-813c-ca1d4846bb05
Ok, I've just realized that for that I should have used MultiSelectController 😅.
Changing selectedOptions in the onItemDelete does not update the widget.
Example:
https://github.com/oi-narendra/multiselect-dropdown/assets/20316179/47fa7d81-12a4-452e-813c-ca1d4846bb05