Justin McCandless
f5ceaf9810
Handle hasStrings on web (#132093)
By default, Flutter web uses the browser's built-in context menu.
<img width="200" src="https://github.com/flutter/flutter/assets/389558/990f99cb-bc38-40f1-9e88-8839bc342da5" />
As of [recently](https://github.com/flutter/engine/pull/38682), it's possible to use a Flutter-rendered context menu like the other platforms.
```dart
void main() {
runApp(const MyApp());
BrowserContextMenu.disableContextMenu();
}
```
But there is a bug (https://github.com/flutter/flutter/issues/129692) that the Paste button is missing and never shows up.
<img width="284" alt="Screenshot 2023-08-07 at 2 39 03 PM" src="https://github.com/flutter/flutter/assets/389558/f632be25-28b1-4e2e-98f7-3bb443f077df">
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](https://github.com/flutter/flutter/pull/87678)).
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](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API) to avoid it. The prompt will show immediately when the EditableText is built, not just when the Paste button is pressed.
<img width="200" src="https://github.com/flutter/flutter/assets/389558/5abdb160-1b13-4f1a-87e1-4653ca19d73e" />
### 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.
<details>
<summary>Video of final behavior with this PR</summary>
https://github.com/flutter/flutter/assets/389558/ed16c925-8111-44a7-99e8-35a09d682748
</details>
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 https://github.com/flutter/engine/pull/43360.
### References
Fixes https://github.com/flutter/flutter/issues/129692
Engine PR to be merged after this: https://github.com/flutter/engine/pull/43360
2023-08-09 20:36:45 +00:00
..
2023-04-07 15:51:05 +00:00
2023-07-20 01:01:01 +00:00
2023-02-02 19:33:57 +00:00
2023-02-02 19:33:57 +00:00
2023-01-31 17:51:49 +00:00
2023-07-05 15:41:13 -07:00
2022-12-20 14:09:55 -08:00
2023-07-05 15:41:13 -07:00
2022-12-20 14:09:55 -08:00
2023-05-15 11:07:30 +02:00
2023-03-02 23:24:02 +00:00
2023-03-14 16:48:07 +00:00
2023-06-08 22:57:19 +00:00
2023-05-09 15:47:16 +00:00
2023-07-06 00:09:01 +00:00
2023-05-02 08:03:02 +00:00
2023-07-07 10:25:35 -07:00
2023-02-02 19:33:57 +00:00
2023-07-06 00:09:01 +00:00
2023-06-30 18:09:56 +00:00
2023-08-07 23:43:03 +00:00
2023-03-09 19:05:32 +00:00
2023-07-27 05:59:17 +00:00
2023-04-07 19:38:52 +00:00
2023-04-07 19:38:52 +00:00
2023-04-07 19:38:52 +00:00
2023-08-02 17:29:50 +00:00
2023-08-07 23:43:03 +00:00
2023-08-07 23:43:03 +00:00
2023-03-22 21:12:22 +00:00
2023-06-28 09:41:58 -07:00
2023-02-02 19:33:57 +00:00
2023-08-07 23:43:03 +00:00
2023-07-17 16:14:08 +00:00
2022-12-20 19:07:15 +00:00
2023-07-31 12:09:27 -07:00
2023-07-17 16:14:08 +00:00
2023-08-07 23:43:03 +00:00
2023-06-09 17:00:14 +00:00
2023-01-05 17:04:15 +00:00
2023-03-22 21:12:22 +00:00
2023-03-14 16:48:07 +00:00
2023-05-22 16:14:35 -07:00
2023-02-02 19:33:57 +00:00
2023-08-07 23:43:03 +00:00
2023-05-23 18:21:10 +00:00
2023-06-27 22:20:15 +02:00
2023-08-09 20:36:45 +00:00
2023-03-08 19:45:49 +00:00
2023-06-13 16:51:22 +00:00
2023-08-07 23:43:03 +00:00
2022-12-14 21:53:20 +00:00
2023-07-06 00:09:01 +00:00
2023-03-27 20:31:49 +00:00
2023-02-02 19:33:57 +00:00
2023-05-15 11:07:30 +02:00
2023-07-17 16:14:08 +00:00
2023-02-28 23:55:58 +00:00
2023-07-20 01:01:01 +00:00
2023-03-29 23:00:24 +00:00
2023-07-06 12:19:18 -07:00
2023-01-20 22:09:06 +00:00
2023-02-13 21:38:27 +00:00
2023-01-31 11:13:59 -08:00
2023-08-07 23:43:03 +00:00
2023-06-16 16:16:36 +00:00
2023-08-07 23:45:19 +00:00
2023-06-01 15:43:18 +00:00
2023-03-01 19:24:18 -08:00
2022-12-20 16:03:21 -08:00
2023-06-28 09:41:58 -07:00
2023-06-09 21:20:50 +00:00
2023-08-07 23:43:03 +00:00
2023-05-16 16:14:23 +00:00
2023-02-02 19:33:57 +00:00
2023-04-04 11:22:22 -07:00
2023-01-20 22:09:06 +00:00
2023-02-23 01:09:51 +00:00
2023-07-17 16:14:08 +00:00
2023-05-26 10:45:56 -07:00
2022-12-20 16:03:21 -08:00
2023-07-17 16:14:08 +00:00
2023-01-20 22:09:06 +00:00
2023-01-20 22:09:06 +00:00
2023-02-02 19:33:57 +00:00
2023-08-07 23:43:03 +00:00
2023-08-07 23:43:03 +00:00
2023-08-07 23:43:03 +00:00
2023-07-06 08:51:06 -07:00
2022-12-20 14:09:55 -08:00
2022-12-20 16:03:21 -08:00
2023-07-06 00:09:01 +00:00
2023-07-17 17:56:07 +00:00
2023-03-27 20:31:49 +00:00
2023-05-03 09:05:16 +00:00
2023-01-24 01:57:00 +00:00
2023-07-17 16:14:08 +00:00
2023-07-17 16:14:08 +00:00
2023-01-31 11:13:59 -08:00
2023-02-02 19:33:57 +00:00
2023-02-01 22:44:00 +00:00
2023-08-08 16:16:52 -07:00
2023-06-28 09:41:58 -07:00
2023-05-05 00:34:04 +00:00
2022-12-20 14:09:55 -08:00
2023-08-07 23:43:03 +00:00
2023-01-31 11:13:59 -08:00
2023-07-17 17:46:00 +00:00
2023-08-09 00:53:10 +00:00
2023-08-07 23:43:03 +00:00
2023-03-22 21:12:22 +00:00
2023-06-30 18:09:56 +00:00
2022-12-20 14:09:55 -08:00
2023-05-24 22:34:06 +00:00
2023-02-02 19:33:57 +00:00
2023-06-28 09:41:58 -07:00
2023-08-07 23:43:03 +00:00
2023-03-07 03:38:59 +00:00
2023-08-07 23:45:19 +00:00
2023-07-06 00:09:01 +00:00
2023-08-07 23:43:03 +00:00
2023-04-19 10:31:36 -07:00
2023-07-06 00:09:01 +00:00
2022-12-20 14:09:55 -08:00
2023-03-15 00:34:34 +00:00
2023-05-15 19:17:11 +00:00
2023-07-17 17:56:07 +00:00
2023-05-19 21:27:24 +00:00
2023-04-24 18:33:24 +00:00
2023-04-24 18:33:24 +00:00
2023-07-13 18:41:56 +00:00
2023-05-19 00:32:26 +00:00
2023-02-02 19:33:57 +00:00
2023-03-27 20:31:49 +00:00
2023-02-02 19:33:57 +00:00
2023-01-25 21:21:28 -08:00
2023-05-15 11:07:30 +02:00
2023-05-16 22:24:03 +00:00
2023-04-10 19:34:51 +00:00
2023-03-15 00:34:34 +00:00
2023-02-28 17:38:29 +00:00
2023-01-03 21:34:08 +00:00
2023-03-09 19:05:32 +00:00
2023-06-14 22:47:06 +00:00
2023-04-18 00:08:07 +00:00
2023-06-28 09:41:58 -07:00
2023-02-28 17:38:29 +00:00
2023-06-28 09:41:58 -07:00
2023-08-07 23:43:03 +00:00
2023-07-06 00:09:01 +00:00
2023-07-07 22:19:09 +00:00
2023-08-08 17:34:17 +00:00
2023-04-19 19:48:12 +00:00
2023-04-07 15:51:05 +00:00
2023-04-07 15:51:05 +00:00
2023-01-20 22:09:06 +00:00
2023-07-06 00:09:01 +00:00
2023-07-06 00:09:01 +00:00
2023-02-02 19:33:57 +00:00
2023-05-15 11:07:30 +02:00
2023-05-31 20:15:52 +00:00
2023-07-31 12:09:27 -07:00
2022-12-20 16:03:21 -08:00
2023-03-09 19:05:32 +00:00
2023-04-12 19:07:08 +00:00
2022-12-20 16:03:21 -08:00
2022-12-20 16:03:21 -08:00
2023-08-07 23:43:03 +00:00
2023-07-06 00:09:01 +00:00
2022-12-20 19:07:15 +00:00
2023-04-24 23:17:36 +00:00
2023-07-24 18:19:03 +00:00
2023-06-28 09:41:58 -07:00
2022-12-20 14:09:55 -08:00
2023-07-24 18:19:03 +00:00
2023-01-03 22:33:55 +00:00
2023-08-07 23:43:03 +00:00
2023-06-28 09:41:58 -07:00
2023-08-07 23:43:03 +00:00
2023-01-03 21:34:08 +00:00
2023-07-06 00:09:01 +00:00
2023-08-07 23:43:03 +00:00
2023-08-07 23:43:03 +00:00
2023-07-06 00:09:01 +00:00
2023-02-02 19:33:57 +00:00
2023-04-05 14:43:56 -07:00
2023-03-29 19:58:58 +00:00
2023-07-17 16:14:08 +00:00
2023-02-02 19:33:57 +00:00
2023-03-30 22:26:51 +00:00
2023-01-31 11:13:59 -08:00
2023-01-20 22:09:06 +00:00
2023-06-28 09:41:58 -07:00
2023-07-17 17:56:07 +00:00
2023-07-19 11:48:01 +02:00
2023-08-07 23:43:03 +00:00
2023-02-02 19:33:57 +00:00
2023-02-02 19:33:57 +00:00
2023-07-17 16:14:08 +00:00
2023-05-26 22:22:21 +00:00
2023-06-28 09:41:58 -07:00
2023-07-26 23:21:05 +00:00
2023-04-06 19:53:50 +00:00
2023-07-17 16:14:08 +00:00
2023-08-07 23:43:03 +00:00
2023-01-17 08:44:08 -05:00
2023-07-28 11:53:26 -04:00
2023-08-02 09:23:57 -04:00
2023-07-17 17:56:07 +00:00
2023-08-07 23:43:03 +00:00