copyLinkToClipboard static method

void copyLinkToClipboard({
  1. required String username,
  2. String? message,
})

Copy Telegram message Link to clipboard

Implementation

static void copyLinkToClipboard({required String username, String? message}) {
  Uri? url;
  try {
    if (message != null && message != '') {
      url =
          Uri.parse('https://t.me/$username?text=${Uri.encodeFull(message)}');
    } else {
      url = Uri.parse('https://t.me/$username');
    }
    if (username != '') {
      // Copy link to clipboard
      Clipboard.setData(ClipboardData(text: url.toString()));
      if (kDebugMode) {
        print('Copied to clipboard: $url');
      }
    }
  } catch (e) {
    if (kDebugMode) {
      print('\x1B[31mGenerating link failed!\nError: $e\x1B[0m');
    }
  }
}