copyToClipboard method

void copyToClipboard([
  1. BuildContext? context,
  2. String? message
])

Copies this string to the clipboard.

If a BuildContext is provided, it will also show a SnackBar with the given message, or "Copied!" by default.

Implementation

void copyToClipboard([BuildContext? context, String? message]) {
  Clipboard.setData(ClipboardData(text: this));
  if (context != null) {
    ScaffoldMessenger.of(
      context,
    ).showSnackBar(SnackBar(content: Text(message ?? 'Copied!')));
  }
}