| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/utils/device_info.dart'; |
| 3 | import 'package:cake_wallet/utils/show_bar.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter/services.dart'; |
| 6 | import 'package:sensitive_clipboard/sensitive_clipboard.dart'; |
| 7 | |
| 8 | class ClipboardUtil { |
| 9 | static Future<void> setSensitiveDataToClipboard(ClipboardData data, |
| 10 | {bool isSensitive = true}) async { |
| 11 | if (isSensitive && DeviceInfo.instance.isMobile) { |
| 12 | await SensitiveClipboard.copy(data.text); |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | return Clipboard.setData(data); |
| 17 | } |
| 18 | |
| 19 | /// Copies [text] to the clipboard and shows a "Copied to Clipboard" |
| 20 | /// confirmation toast. Prefer this for any user-facing copy action so the |
| 21 | /// feedback stays consistent across the app. |
| 22 | static Future<void> copyToClipboard( |
| 23 | BuildContext context, |
| 24 | String text, { |
| 25 | bool isSensitive = false, |
| 26 | }) async { |
| 27 | await setSensitiveDataToClipboard(ClipboardData(text: text), isSensitive: isSensitive); |
| 28 | if (context.mounted) { |
| 29 | showBar<void>(context, S.of(context).copied_to_clipboard); |
| 30 | } |
| 31 | } |
| 32 | } |