Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Aug 7, 2023

By default, Flutter web uses the browser's built-in context menu.

As of recently, it's possible to use a Flutter-rendered context menu like the other platforms.

void main() {
  runApp(const MyApp());
  BrowserContextMenu.disableContextMenu();
}

But there is a bug (#129692) that the Paste button is missing and never shows up.

Screenshot 2023-08-07 at 2 39 03 PM

The reason why it's missing is that Flutter first checks if there is any pasteable text on the clipboard before deciding to show the Paste button using the hasStrings platform channel method, but that was never implemented for web (original hasStrings PR).

So let's just implement hasStrings for web? No, because Chrome shows a permissions prompt when the clipboard is accessed, and there is no browser clipboard API to avoid it. The prompt will show immediately when the EditableText is built, not just when the Paste button is pressed.

This PR's solution

Instead, before implementing hasStrings for web, this PR disables the hasStrings check for web. The result is that users will always see a paste button, even in the (unlikely) case that they have nothing pasteable on the clipboard. However, they will not see a permissions dialog until they actually click the Paste button. Subsequent pastes don't show the permission dialog.

Video of final behavior with this PR
Screen.Recording.2023-08-07.at.2.27.35.PM.mov

I think this will be the desired behavior for the vast majority of app developers. Those that want different behavior can use hasStrings themselves, which will be implemented in flutter/engine#43360.

References

Fixes #129692
Engine PR to be merged after this: flutter/engine#43360

@justinmc justinmc self-assigned this Aug 7, 2023
@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Aug 7, 2023
@justinmc justinmc changed the title Web hasStrings hasStrings on web Aug 7, 2023
@justinmc justinmc changed the title hasStrings on web Handle hasStrings on web Aug 7, 2023
@justinmc justinmc requested review from mdebbar and yjbanov August 7, 2023 22:04
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and the solution makes sense!

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if LGT @mdebbar

@github-actions github-actions bot added the f: material design flutter/packages/flutter/material repository. label Aug 9, 2023
@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 9, 2023
@justinmc
Copy link
Contributor Author

justinmc commented Aug 9, 2023

Thanks for the reviews and for helping to figure this out!

@auto-submit auto-submit bot merged commit f5ceaf9 into flutter:master Aug 9, 2023
@justinmc justinmc deleted the web-has-strings branch August 9, 2023 20:58
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

paste option doesn't show in web when using BrowserContextMenu.disableContextMenu

3 participants