dispatchSelectionEvent method

  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:
      _extendSelectionInProgress = false;
      result = handleSelectionEdgeUpdate(event as SelectionEdgeUpdateEvent);
    case SelectionEventType.clear:
      _extendSelectionInProgress = false;
      result = handleClearSelection(event as ClearSelectionEvent);
    case SelectionEventType.selectAll:
      _extendSelectionInProgress = false;
      result = handleSelectAll(event as SelectAllSelectionEvent);
    case SelectionEventType.selectWord:
      _extendSelectionInProgress = false;
      result = handleSelectWord(event as SelectWordSelectionEvent);
    case SelectionEventType.granularlyExtendSelection:
      _extendSelectionInProgress = true;
      result = handleGranularlyExtendSelection(event as GranularlyExtendSelectionEvent);
    case SelectionEventType.directionallyExtendSelection:
      _extendSelectionInProgress = true;
      result = handleDirectionallyExtendSelection(event as DirectionallyExtendSelectionEvent);
  }
  _isHandlingSelectionEvent = false;
  _updateSelectionGeometry();
  return result;
}