handleCopy method Null safety

void handleCopy(
  1. TextSelectionDelegate delegate,
  2. ClipboardStatusNotifier? clipboardStatus
)

Copy the current selection of the text field managed by the given delegate to the Clipboard. Then, move the cursor to the end of the text (collapsing the selection in the process), and hide the toolbar.

This is called by subclasses when their copy affordance is activated by the user.

Implementation

void handleCopy(TextSelectionDelegate delegate, ClipboardStatusNotifier? clipboardStatus) {
  final TextEditingValue value = delegate.textEditingValue;
  Clipboard.setData(ClipboardData(
    text: value.selection.textInside(value.text),
  ));
  clipboardStatus?.update();
  delegate.bringIntoView(delegate.textEditingValue.selection.extent);

  switch (defaultTargetPlatform) {
    case TargetPlatform.iOS:
      // Hide the toolbar, but keep the selection and keep the handles.
      delegate.hideToolbar(false);
      return;
    case TargetPlatform.macOS:
    case TargetPlatform.android:
    case TargetPlatform.fuchsia:
    case TargetPlatform.linux:
    case TargetPlatform.windows:
      // Collapse the selection and hide the toolbar and handles.
      delegate.userUpdateTextEditingValue(
        TextEditingValue(
          text: value.text,
          selection: TextSelection.collapsed(offset: value.selection.end),
        ),
        SelectionChangedCause.toolBar,
      );
      delegate.hideToolbar();
      return;
  }
}