Clipboard.setData(ClipboardData(text: textToCopy));
is working fine on flutter web when visiting via desktop browsers, but is nonfunctional on mobile (iOS Chrome & Safari).
Are there any work arounds?
I’ve tried a few other packages besides the classic flutter services, but they all had the same issue.
2
Answers
I have also encountered the same issue but for reading text from the clipboard.
Clipboard.getData(Clipboard.kTextPlain)
does not work on Flutter web for iOS or Android browsersHowever, I found a workaround that works for me that uses javascript.
I will paste my code here
Conclusion – I hope this could help someone and wish that
Clipboard.getData()
could be fixed in the future but I am using this workaround for now which seems to workPlease note that the
window.navigator.clipboard
could be undefined as it requires a secure origin (HTTPS or localhost)reference: navigator.clipboard is undefined
Not sure if it is a bug, seems like apple is blocking writing to clipboard if there wasn’t a recent user action.
Similar issue:
https://github.com/flutter/flutter/issues/106046
So it’s probably apple browser security related.
For me copying to clipboard after a future delayed of 1 ms it works
After a future delayed of 1 second it does not work.