Skip to content

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Jun 26, 2025

When readOnly is true, there is no TextInputConnection, so the SystemContextMenu can't be shown. Instead, this shows the Flutter-drawn context menu.

This video shows the change. You can slightly tell that the system context menu is shown when readOnly is false and the Flutter-drawn context menu is shown when it is true.

Screen.Recording.2025-06-26.at.2.31.43.PM.mov

This is the same root cause as #169238.

Fixes #170521

@justinmc justinmc self-assigned this Jun 26, 2025
@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. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Jun 26, 2025
@justinmc justinmc requested a review from Renzo-Olivares June 26, 2025 22:35
EditableTextState editableTextState,
) {
if (defaultTargetPlatform == TargetPlatform.iOS && SystemContextMenu.isSupported(context)) {
if (defaultTargetPlatform == TargetPlatform.iOS &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should share this logic somewhere, maybe under EditableTextState as supportsSystemContextMenu? Not required for this PR but just a thought I had since I see the same logic duplicated across multiple files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. SystemContextMenu imports EditableText, so I made it a static method on SystemContextMenu.

if (defaultTargetPlatform == TargetPlatform.iOS && SystemContextMenu.isSupported(context)) {
if (defaultTargetPlatform == TargetPlatform.iOS &&
SystemContextMenu.isSupported(context) &&
!editableTextState.widget.readOnly) {
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares Jun 27, 2025

Choose a reason for hiding this comment

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

It might be helpful to have a comment here on why the system context menu is not supported with readOnly set to true (here and in other files/ or a centralized place).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added on SystemContextMenu.isSupportedByField.

@alex-medinsh
Copy link
Contributor

there is no TextInputConnection, so the SystemContextMenu can't be shown

Could you please provide some details on what is blocking us from implementing native context menu without a text connection? I am not very familiar with native iOS development.

It seems to me that having a native context menu in all cases would be even more important with the release of iOS 26, since IIUC it changes the appearance of the context menu, while Flutter's context menu still resembles the iOS 18 one.

@justinmc
Copy link
Contributor Author

justinmc commented Jul 7, 2025

@hellohuanlin What would it take to be able to show the system context menu without an active UITextView? Originally we used it to determine which buttons to show, but now that can be specified by the user, so maybe it's easier to do now.

@hellohuanlin
Copy link
Contributor

@hellohuanlin What would it take to be able to show the system context menu without an active UITextView? Originally we used it to determine which buttons to show, but now that can be specified by the user, so maybe it's easier to do now.

The native edit menu is powered by an UIEditMenuInteraction, which needs to be added to a UIView (for our case, it's the backing UITextInputView).

So to support the non-editable text (which doesn't have a backing UITextInputView, we would have to add it to other views on screen (e.g. FlutterView). We should think about how to reuse the code. It won't be a trivial change, but should be doable.

@justinmc
Copy link
Contributor Author

justinmc commented Jul 7, 2025

Thanks @hellohuanlin, I created this issue to track: #171732

@justinmc justinmc requested a review from Renzo-Olivares July 7, 2025 22:23

expect(SystemContextMenu.isSupported(buildContext), isFalse);
},
skip: kIsWeb, // [intended]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add reason for skipping like // [intended] on web the browser handles the context menu. here and below.

EditableTextState editableTextState,
) {
if (defaultTargetPlatform == TargetPlatform.iOS && SystemContextMenu.isSupported(context)) {
if (defaultTargetPlatform == TargetPlatform.iOS &&
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be changed to SystemContextMenu.isSupportedByField(editableTextState) I think.

justinmc added 3 commits July 8, 2025 11:15
I think I had misread the previous analyzer failure as coming from the
wrong file.
@justinmc justinmc force-pushed the read-only-context-menu branch from 9401ef4 to f9b467e Compare July 8, 2025 18:21
@justinmc justinmc force-pushed the read-only-context-menu branch from 894bb27 to bfb4912 Compare July 14, 2025 22:08
@justinmc justinmc removed request for a team July 16, 2025 20:13
@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 17, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jul 17, 2025
Merged via the queue into flutter:master with commit f16f6d7 Jul 17, 2025
74 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 17, 2025
@justinmc justinmc deleted the read-only-context-menu branch July 17, 2025 20:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 18, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jul 18, 2025
flutter/flutter@9c626d9...440713c

2025-07-18 [email protected] Add OS version support section to plugin docs (flutter/flutter#172316)
2025-07-18 [email protected] Roll Dart SDK from 7fcc5f48c335 to fe2232bd5b9f (2 revisions) (flutter/flutter#172339)
2025-07-18 [email protected] Refactor handling of frame waiting. (flutter/flutter#172277)
2025-07-18 [email protected] Roll pub packages (flutter/flutter#172332)
2025-07-17 [email protected] Refactor and forbid `base/exit.dart` outside of `lib/runner.dart` (flutter/flutter#171923)
2025-07-17 [email protected] Use UTC timezone for `stamp_command_test` to avoid local TZ flakes (flutter/flutter#172319)
2025-07-17 [email protected] [web] Add tests for unified platform view embedding behavior (flutter/flutter#172313)
2025-07-17 [email protected] Platform views shouldn't receive pointer events when not laid out (flutter/flutter#172043)
2025-07-17 [email protected] Fix Size.isEmpty description (flutter/flutter#172021)
2025-07-17 [email protected] feat: Add `maxCount` parameter to `Badge.count` constructor. (flutter/flutter#171054)
2025-07-17 [email protected] add `debugPaintTextLayoutBoxes` for debugging text layout (flutter/flutter#168876)
2025-07-17 [email protected] Roll Packages from 4a231ae to cb8fef6 (31 revisions) (flutter/flutter#172303)
2025-07-17 [email protected] Fix mutating Paint bug (flutter/flutter#171180)
2025-07-17 [email protected] No SystemContextMenu when readOnly is true (flutter/flutter#171242)
2025-07-17 [email protected] Add a getter to get the recorder used by painting context (flutter/flutter#170223)
2025-07-17 [email protected] [Impeller] Add missing SetPipeline call for the vertices uber pipeline in AtlasContents (flutter/flutter#172273)
2025-07-17 [email protected] Roll Dart SDK from 486f9c0663bc to 7fcc5f48c335 (1 revision) (flutter/flutter#172279)
2025-07-17 [email protected] Roll Skia from 3673a1f26a63 to 9587301e33bc (3 revisions) (flutter/flutter#172281)
2025-07-17 [email protected] Fix a race in FlutterEngineTest.CanLogToStdout (flutter/flutter#172025)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
azatech pushed a commit to azatech/flutter that referenced this pull request Jul 28, 2025
When readOnly is true, there is no TextInputConnection, so the
SystemContextMenu can't be shown. Instead, this shows the Flutter-drawn
context menu.

This video shows the change. You can slightly tell that the system
context menu is shown when readOnly is false and the Flutter-drawn
context menu is shown when it is true.



https://github.com/user-attachments/assets/91480fa4-cce6-4d63-ae11-df72a229da73


This is the same root cause as
flutter#169238.

Fixes flutter#170521
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
…r#9646)

flutter/flutter@9c626d9...440713c

2025-07-18 [email protected] Add OS version support section to plugin docs (flutter/flutter#172316)
2025-07-18 [email protected] Roll Dart SDK from 7fcc5f48c335 to fe2232bd5b9f (2 revisions) (flutter/flutter#172339)
2025-07-18 [email protected] Refactor handling of frame waiting. (flutter/flutter#172277)
2025-07-18 [email protected] Roll pub packages (flutter/flutter#172332)
2025-07-17 [email protected] Refactor and forbid `base/exit.dart` outside of `lib/runner.dart` (flutter/flutter#171923)
2025-07-17 [email protected] Use UTC timezone for `stamp_command_test` to avoid local TZ flakes (flutter/flutter#172319)
2025-07-17 [email protected] [web] Add tests for unified platform view embedding behavior (flutter/flutter#172313)
2025-07-17 [email protected] Platform views shouldn't receive pointer events when not laid out (flutter/flutter#172043)
2025-07-17 [email protected] Fix Size.isEmpty description (flutter/flutter#172021)
2025-07-17 [email protected] feat: Add `maxCount` parameter to `Badge.count` constructor. (flutter/flutter#171054)
2025-07-17 [email protected] add `debugPaintTextLayoutBoxes` for debugging text layout (flutter/flutter#168876)
2025-07-17 [email protected] Roll Packages from 4a231ae to cb8fef6 (31 revisions) (flutter/flutter#172303)
2025-07-17 [email protected] Fix mutating Paint bug (flutter/flutter#171180)
2025-07-17 [email protected] No SystemContextMenu when readOnly is true (flutter/flutter#171242)
2025-07-17 [email protected] Add a getter to get the recorder used by painting context (flutter/flutter#170223)
2025-07-17 [email protected] [Impeller] Add missing SetPipeline call for the vertices uber pipeline in AtlasContents (flutter/flutter#172273)
2025-07-17 [email protected] Roll Dart SDK from 486f9c0663bc to 7fcc5f48c335 (1 revision) (flutter/flutter#172279)
2025-07-17 [email protected] Roll Skia from 3673a1f26a63 to 9587301e33bc (3 revisions) (flutter/flutter#172281)
2025-07-17 [email protected] Fix a race in FlutterEngineTest.CanLogToStdout (flutter/flutter#172025)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
When readOnly is true, there is no TextInputConnection, so the
SystemContextMenu can't be shown. Instead, this shows the Flutter-drawn
context menu.

This video shows the change. You can slightly tell that the system
context menu is shown when readOnly is false and the Flutter-drawn
context menu is shown when it is true.



https://github.com/user-attachments/assets/91480fa4-cce6-4d63-ae11-df72a229da73


This is the same root cause as
flutter#169238.

Fixes flutter#170521
@hasanmhallak
Copy link
Contributor

when would this land on stable?

mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
When readOnly is true, there is no TextInputConnection, so the
SystemContextMenu can't be shown. Instead, this shows the Flutter-drawn
context menu.

This video shows the change. You can slightly tell that the system
context menu is shown when readOnly is false and the Flutter-drawn
context menu is shown when it is true.



https://github.com/user-attachments/assets/91480fa4-cce6-4d63-ae11-df72a229da73


This is the same root cause as
flutter#169238.

Fixes flutter#170521
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
When readOnly is true, there is no TextInputConnection, so the
SystemContextMenu can't be shown. Instead, this shows the Flutter-drawn
context menu.

This video shows the change. You can slightly tell that the system
context menu is shown when readOnly is false and the Flutter-drawn
context menu is shown when it is true.



https://github.com/user-attachments/assets/91480fa4-cce6-4d63-ae11-df72a229da73


This is the same root cause as
flutter#169238.

Fixes flutter#170521
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 f: cupertino flutter/packages/flutter/cupertino repository 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.

Selecting text in readOnly TextField on iOS throws assertion exception

5 participants