cutSelection method Null safety

void cutSelection(
  1. SelectionChangedCause cause
)

Cut current selection to Clipboard.

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

Implementation

void cutSelection(SelectionChangedCause cause) {
  if (_readOnly) {
    return;
  }
  final TextSelection selection = textSelectionDelegate.textEditingValue.selection;
  final String text = textSelectionDelegate.textEditingValue.text;
  assert(selection != null);
  if (!selection.isCollapsed) {
    Clipboard.setData(ClipboardData(text: selection.textInside(text)));
    _setTextEditingValue(
      TextEditingValue(
        text: selection.textBefore(text) + selection.textAfter(text),
        selection: TextSelection.collapsed(offset: math.min(selection.start, selection.end)),
      ),
      cause,
    );
  }
}