Skip to content

Fix for duplicate values using setState with initially selected items #16

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class _SimpleMultiSelectContainerState<T>

@override
void didUpdateWidget(MultiSelectContainer<T> oldWidget) {
_addInitiallySelectedItemsToSelectedList();
_setPerpetualSelectedItemsCount();
if (widget.controller != null) {
widget.controller!.deselectAll = oldWidget.controller!.deselectAll;
widget.controller!.getSelectedItems =
Expand All @@ -129,7 +129,7 @@ class _SimpleMultiSelectContainerState<T>
super.didUpdateWidget(oldWidget);
}

//add initially selected items and find perpetual selected items count
// add initially selected items and find perpetual selected items count
void _addInitiallySelectedItemsToSelectedList() {
final initiallySelected = _items
.where((item) => item.selected || item.perpetualSelected)
Expand All @@ -140,6 +140,13 @@ class _SimpleMultiSelectContainerState<T>
setState(() {});
}

// find perpetual selected items count
void _setPerpetualSelectedItemsCount() {
_perpetualSelectedItemsCount =
_items.where((item) => item.perpetualSelected).length;
setState(() {});
}

// Deselect all selected items excluding Perpetual Selected Items
// for controller deselect call back
void _deSelectAll() {
Expand Down