updateSelected method
Updates the selection state for multiple items in a batch operation.
This method is optimized for drag selection operations where multiple items may change state simultaneously. It provides several advantages over individual toggle calls:
Features
- Batch Processing: Updates all items in a single operation
- Change Detection: Only processes items that actually changed
- Haptic Feedback: Optional tactile feedback for state changes
- Single Notification: Notifies listeners once after all updates
Haptic Feedback
When enableHapticFeedback is true, provides subtle vibration feedback
for each item whose selection state changes. This enhances user experience
during drag selection by providing tactile confirmation of selections.
Performance
More efficient than multiple toggle calls because:
- Single listener notification instead of per-item notifications
- Early exit for unchanged items
- Direct list assignment without bounds checking per item
Implementation
void updateSelected(List<bool> newSelection, bool enableHapticFeedback) {
for (int i = 0; i < newSelection.length; i++) {
if (newSelection[i] != _selected[i]) {
_selected[i] = newSelection[i];
if (enableHapticFeedback) {
HapticFeedback.lightImpact();
}
}
}
notifyListeners();
}