expandSelectionToEnd method Null safety

void expandSelectionToEnd(
  1. SelectionChangedCause cause
)

Expand the current selection to the end of the field.

The selection will never shrink. The TextSelection.extentOffset will TextSelection.baseOffset and TextSelection.extentOffset.

If selectionEnabled is false, keeps the selection collapsed and moves it to the end.

The given SelectionChangedCause indicates the cause of this change and will be passed to onSelectionChanged.

See also:

Implementation

// always be at the end of the field, regardless of the original order of
/// [TextSelection.baseOffset] and [TextSelection.extentOffset].
///
/// If [selectionEnabled] is false, keeps the selection collapsed and moves it
/// to the end.
///
/// {@macro flutter.rendering.RenderEditable.cause}
///
/// See also:
///
///   * [expandSelectionToStart], which is same but in the opposite direction.
void expandSelectionToEnd(SelectionChangedCause cause) {
  assert(selection != null);

  if (selection!.extentOffset == _plainText.length) {
    return;
  }
  if (!selectionEnabled) {
    return moveSelectionToEnd(cause);
  }

  final int firstOffset = math.max(0, math.min(
    selection!.baseOffset,
    selection!.extentOffset,
  ));
  final TextSelection nextSelection = TextSelection(
    baseOffset: firstOffset,
    extentOffset: _plainText.length,
  );
  _setSelection(nextSelection, cause);
}