-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't paste into TextField when copying from Samsung Notes, MS Word and MS Excel on Android #74320
Comments
Issue replicable on latest master. The text copied from Samsung Notes cannot be pasted in Flutter's textfield. flutter doctor -v
|
I have this problem on my app too. I've experienced it while trying to paste a text that I've copied from Samsung Internet browser. I was about to create an issue for it but I've come across this one. I've also reproduced it with Samsung Notes as @agustka did. Could this be a problem with Samsung's apps? |
I was able to reproduce on a non-Samsung phone. I run LineageOS on a OnePlus 3t. I created a quick app per the bug. I was able to copy and paste properly from Chrome, Keep, and Google Docs. I installed Microsoft Word from the Play store. I opened a document, copied text. I was unable to paste into my text box. I have not investigated further, but, given that it is not Samsung specific, it could be reproduced in an emulator or other device and be debugged. |
To update -- I ran this in the debugger and got the following error: |
I can also reproduce it. |
@harriseldon I have seen the same stack trace. This instance starts from a programmatic call to I can't be sure what app the text was copied from though as this is a live crash report. crashlytics logs:
This is called on the first Device ListDevice 1Brand: samsung Operating SystemVersion: 8.1.0 Device 2Brand: HUAWEI Operating SystemVersion: 10 |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
I have the same issue. Flutter Doctor (I don't build for web): [✓] Flutter (Channel stable, 2.2.3, on Linux, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) [✓] Android Studio (version 2020.3) [✓] Connected device (1 available) ! Doctor found issues in 1 category. ===
|
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
@aleripe This issue still open and haven't been assigned for fix yet, but I'll try to raise it up with concerned team. |
Thanks a lot, this is greatly impacting and so low level there's actually no workaround for it. |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
i have the same issue, I think I know what's the matter. Samsung has a non-standard clipboard that can contain: text, pictures, etc. because, for example, if you copy from chrome, then everything works fine, if you copy from samsung notes, nothing works. The problem is in the type of data being copied: from chrome, this is text/plain from another place, it may be different! The question is how to find out the type of clipboard from samsung notes or other place? |
As far as it seems, this issue has a deeper level of the problem than just being unable to copy and paste from some apps like Samsung Notes. First of all, Flutter's representation of the clipboard seems too simplistic which might be one of the reasons why this issue happens in the first place. It seems that Clipboard expects all the data to be just texts which is pretty nonsensical, since in the clipboard nowadays not only texts are expected, but also images, other objects, videos, and some objects might have multiple formats for the same object (e.g., HTML text, same text in plain text format, and so on). Furthermore, multiple objects can exist in the clipboard at once. This should be known for Android developers, since it is them who developed the Android this way. So, the first potential step for Flutter to actually fix this issue would be to re-engineer the Clipboard to support multiple objects and multiple formats. When better understanding what happens here, it would be very nice if Flutter developers would not treat this issue as just another bug which can be fixed, but also would rethink how they implement the Clipboard, and make sure it is more robust than it is now. I believe they can fix this issue without too much effort, but maybe it would be better to provide a better abstraction for the Clipboard itself, and then use it in other widgets where it is relevant? Now about one more workaround which might actually help developers to solve their users' problems. There is this package: https://pub.dev/packages/super_clipboard . They represent the Clipboard in a more robust way than current one from Flutter. The drawback of using this package is that it requires additionally for us to set-up NDK, and install Rust which makes the set-up a bit harder than usually we would expect. But after doing all of these things, it becomes pretty simple to use this package. Then, we can represent our TextFormField with wrapping it using IgnorePointer, GestureDetector widgets. Basically, we would need to ignore the default Flutter events, and instead of Flutter's context menu provide our own menu. The idea would be like this:
The drawback here might be that we would need to tweak this menu to retain the native look and feel. As you can see, through the GestureDetector we reimplement the following:
And finally, we have _showMenu, and _paste methods:
In the _paste method, we paste the contents from any app to our own text field using the package mentioned above. By setting the value of TextEditingController of the clipboard, we simulate the paste event like this. The example code with the demo app that can be built for Android can be found here: https://github.com/vaidotasstrazdas/textfield_paste Finally, this is just a workaround, thus should be used with your own risks, and also other Flutter related things must be kept in mind. But for apps were this functionality is very important probably this workaround can be tweaked to a pretty usable version. |
Same problem happening with our users. Detected in Samsung, Motorola and Xiaomi. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Based on the docs, it sounds like we need to check that it's a |
Capturing from some internal discussion, it might be useful to address this in two steps:
|
First step here for me was to reproduce this, and I was able to do so successfully on a Pixel 3A trying to copy from the MS Word Android app to a Flutter Going to dig into this reproduction a bit more to see what the actual URI is since it's likely not one containing |
Dug into the repro a bit and discovered that the issue is actually unlikely that the paste items with URIs causing the issues noted in this bug aren't content URIS. In the case of my repro (paste from MS word), the URI does contain Thus, the error being thrown on this line in Flutter is actually being caused because we are asking specifically for the The Flutter code concerned here was introduced in flutter/engine#21290 and I believe the I will need to test this fix out for the MS Excel and Samsung Notes cases, and assuming it works, will follow up with a PR. |
(At least one case above (see the link in my comment) is showing a |
Ah thank you @stuartmorgan for calling this to my attention, I didn't catch that! I was just able to reproduce this on a Samsung tablet and did see the URI is So, there are two cases:
|
Would like to note here that https://developer.android.com/develop/ui/views/touch-and-input/copy-paste has been a super helpful guide for explaining how copying/pasting works in Android. My PR is inspired by https://developer.android.com/develop/ui/views/touch-and-input/copy-paste#PastePlainText |
Tested out the fix with |
flutter/engine#48166 up for review. Landing it will close this issue, with the idea being that new issues can be opened for other apps throwing errors not handled by that fix! |
Review had a merge conflict that needs to be resolved then this will be fixed. |
… URI (#48166) Adds a check to retrieve explicit text from Clipboard items via [`getText`](https://developer.android.com/reference/android/content/ClipData.Item#getText()) before attempting to retrieve data if the Clipboard item (`ClipData.Item`) has an associated URI. Also adds more error handling for edge cases concerning URIs (the URI not having the content scheme or being null). Fixes flutter/flutter#74320. Some content providers will not send URIs containing the `text/*` pattern or have the content scheme (`content://`), but ultimately we should expect Clipboard items to either fall **not** into one of those categories or have an explicit textual value available via `getText`. In case this is not true, though, checks for non-content URIs and null URIs are added, as well :) Tested on a Samsung tablet with pasting from MS Word, MS Excel, and Samsung Notes. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Merge conflict fixed and PR landed. Please file another issue if copy/paste issues come up with other apps so we can take a look! |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
Expected results:
Long press menu with paste option should appear
Actual results:
Nothing happens
main.dart:
Logs
The text was updated successfully, but these errors were encountered: