Skip to content

Instantly share code, notes, and snippets.

@AlexV525
Forked from bergwerf/clipboard.dart
Created July 2, 2020 06:06
Show Gist options
  • Save AlexV525/7a84cc1ebc7bd9c47403eceec6651a93 to your computer and use it in GitHub Desktop.
Save AlexV525/7a84cc1ebc7bd9c47403eceec6651a93 to your computer and use it in GitHub Desktop.
Copy to web clipboard in Flutter For the Web
/// A hack to copy a string to the clipboard.
bool _copyToClipboardHack(String text) {
final textarea = new TextAreaElement();
document.body.append(textarea);
textarea.style.border = '0';
textarea.style.margin = '0';
textarea.style.padding = '0';
textarea.style.opacity = '0';
textarea.style.position = 'absolute';
textarea.readOnly = true;
textarea.value = text;
textarea.select();
final result = document.execCommand('copy');
textarea.remove();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment