copySelection method Null safety

  1. @override
void copySelection(
  1. SelectionChangedCause cause
)
override

Copy current selection to Clipboard.

Implementation

@override
void copySelection(SelectionChangedCause cause) {
  final TextSelection selection = textEditingValue.selection;
  assert(selection != null);
  if (selection.isCollapsed || widget.obscureText) {
    return;
  }
  final String text = textEditingValue.text;
  Clipboard.setData(ClipboardData(text: selection.textInside(text)));
  if (cause == SelectionChangedCause.toolbar) {
    bringIntoView(textEditingValue.selection.extent);
    hideToolbar(false);

    switch (defaultTargetPlatform) {
      case TargetPlatform.iOS:
      case TargetPlatform.macOS:
      case TargetPlatform.linux:
      case TargetPlatform.windows:
        break;
      case TargetPlatform.android:
      case TargetPlatform.fuchsia:
        // Collapse the selection and hide the toolbar and handles.
        userUpdateTextEditingValue(
          TextEditingValue(
            text: textEditingValue.text,
            selection: TextSelection.collapsed(offset: textEditingValue.selection.end),
          ),
          SelectionChangedCause.toolbar,
        );
        break;
    }
  }
  _clipboardStatus?.update();
}