copyToClipboard static method

bool copyToClipboard(
  1. String? text, {
  2. String? successMessage,
  3. BuildContext? context,
})

拷贝文本内容到剪切板

Implementation

static bool copyToClipboard(String? text,
    {String? successMessage, BuildContext? context}) {
  if (text != null && text.isNotEmpty) {
    Clipboard.setData(ClipboardData(text: text));
    if (context != null) {
      ScaffoldMessenger.of(context).showSnackBar(SnackBar(
          duration: const Duration(seconds: 1),
          content: Text(successMessage ?? "copy success")));
      return true;
    } else {
      return false;
    }
  }
  return false;
}