import 'package:flutter/foundation.dart'; class Selection extends ChangeNotifier { bool _isSelecting = false; bool get isSelecting => _isSelecting; final Set _selection = {}; Set get selection => _selection; void browse() { clearSelection(); _isSelecting = false; notifyListeners(); } void select() { _isSelecting = true; notifyListeners(); } bool isSelected(Iterable items) => items.every(selection.contains); void addToSelection(Iterable items) { _selection.addAll(items); notifyListeners(); } void removeFromSelection(Iterable items) { _selection.removeAll(items); notifyListeners(); } void clearSelection() { _selection.clear(); notifyListeners(); } void toggleSelection(T item) { if (_selection.isEmpty) select(); if (!_selection.remove(item)) _selection.add(item); notifyListeners(); } }