deleteForward method Null safety

void deleteForward(
  1. SelectionChangedCause cause

Deletes in the forward direction, from the current selection in textSelectionDelegate.

This method operates on the text/selection contained in textSelectionDelegate, and does not depend on selection.

If the selection is collapsed, deletes a single character after the cursor.

If the selection is not collapsed, deletes the selection.

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

See also:

  • delete, which is same but in the opposite direction.


void deleteForward(SelectionChangedCause cause) {
  // TODO(LongCatIsLooong): remove this method from RenderEditable.
  final TextEditingValue controllerValue = textSelectionDelegate.textEditingValue;
  final TextSelection selection = controllerValue.selection;

  if (!selection.isValid || _readOnly || _deleteNonEmptySelection(cause)) {

  final String textAfter = selection.textAfter(controllerValue.text);
  if (textAfter.isEmpty) {

  final String textBefore = selection.textBefore(controllerValue.text);
  final int characterBoundary = nextCharacter(0, textAfter);
  final TextRange composing = controllerValue.composing;
  final TextRange newComposingRange = !composing.isValid || composing.isCollapsed
    ? TextRange.empty
    : TextRange(
      start: composing.start - (composing.start - textBefore.length).clamp(0, characterBoundary),
      end: composing.end - (composing.end - textBefore.length).clamp(0, characterBoundary),
      text: textBefore + textAfter.substring(characterBoundary),
      selection: selection,
      composing: newComposingRange,