dispatchSelectionEvent method Null safety

  1. @override
SelectionResult dispatchSelectionEvent(
  1. SelectionEvent event
)
override

Handles the SelectionEvent sent to this object.

The subclasses need to update their selections or delegate the SelectionEvents to their subtrees.

The events are subclasses of SelectionEvent. Check SelectionEvent.type to determine what kinds of event are dispatched to this handler and handle them accordingly.

See also:

Implementation

@override
SelectionResult dispatchSelectionEvent(SelectionEvent event) {
  final bool selectionWillbeInProgress = event is! ClearSelectionEvent;
  if (!_selectionInProgress && selectionWillbeInProgress) {
    // Sort the selectable every time a selection start.
    selectables.sort(compareOrder);
  }
  _selectionInProgress = selectionWillbeInProgress;
  _isHandlingSelectionEvent = true;
  late SelectionResult result;
  switch (event.type) {
    case SelectionEventType.startEdgeUpdate:
    case SelectionEventType.endEdgeUpdate:
      result = handleSelectionEdgeUpdate(event as SelectionEdgeUpdateEvent);
      break;
    case SelectionEventType.clear:
      result = handleClearSelection(event as ClearSelectionEvent);
      break;
    case SelectionEventType.selectAll:
      result = handleSelectAll(event as SelectAllSelectionEvent);
      break;
    case SelectionEventType.selectWord:
      result = handleSelectWord(event as SelectWordSelectionEvent);
      break;
  }
  _isHandlingSelectionEvent = false;
  _updateSelectionGeometry();
  return result;
}