Repository navigation
iOS "Scribble" feature: assertion error when using SystemContextMenu #159259
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.platform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Description
Steps to reproduce
- Compile and run the code sample from below on an iPad. The sample simply displays a TextField that is using a
SystemContextMenu. - Enter some text into the text field.
- Use the Apple Pencil to select some text or use any other "Scribble" feature.
Expected results
One would expect this to "just work". 😉
Actual results
Sooner or later (in my tests, always really quickly) you'll run into the assertion error Attempted to show while another instance was still visible. in the SystemContextMenuController (to be exact, here).
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 450),
child: TextField(
scribbleEnabled: true,
contextMenuBuilder: (_, ets) =>
SystemContextMenu.editableText(editableTextState: ets),
),
),
),
),
);
}
}Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.24.5, on macOS 15.1.1 24B91 darwin-arm64, locale en-US)
• Flutter version 3.24.5 on channel stable at /Users/redge/Shared/SDKs/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision dec2ee5c1f (8 days ago), 2024-11-13 11:13:06 -0800
• Engine revision a18df97ca5
• Dart version 3.5.4
• DevTools version 2.37.3
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/redge/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16B40
• CocoaPods version 1.16.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
[✓] VS Code (version 1.95.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.101.20241031
[✓] Connected device (4 available)
• Daniels iPad Air (mobile) • 00008112-000108C13E81A01E • ios • iOS 18.1 22B83
• macOS (desktop) • macos • darwin-arm64 • macOS 15.1.1 24B91 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.1.1 24B91 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.85
[✓] Network resources
• All expected network resources are available.
• No issues found!Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.platform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Activity
darshankawar commentedon Nov 21, 2024
Thanks for the report. I currently don't have physical ipad / latest version with scribble feature, so can't verify this, but based on the report, keeping it open and labeling for team's tracking.
jmagman commentedon Nov 21, 2024
cc @hellohuanlin the message is framework-side but I'm guessing the problem is in the engine since it's specific to Apple Pencil.
flutter-team-archive/engine#50095
justinmc commentedon Nov 23, 2024
@PrimaryFeather I have a suspicion that this is caused by hot restarting or hot reloading. Can you try to reproduce from a fresh start?
We maintain a static instance of the last system context menu shown here in SystemContextMenuController. This was maybe a sketchy choice... I don't think it will get cleared out on hot reload, or in between tests.
PrimaryFeather commentedon Nov 25, 2024
@justinmc Unfortunately, that's not it - I just tried it out, and the issue pops up even after a fresh start.
However, I could isolate the issue a little further. In my test, I first enter some text (either via keyboard or via Scribble), and then I try to select some text with the stylus (by simply striking it through). When I do that, the context menu quickly closes and opens and again while moving over the first word; that looks weird, but it doesn't cause an exception. When the stylus leaves the first word and moves over the second one, the exception comes up.
I recorded a short video that shows the issue. Of course, you can't see the stylus and the exception, but the latter is the reason why the image is freezing at the end.
system-context-menu-issue.mov
justinmc commentedon Nov 25, 2024
Thank you for the clarification! Ok here's my new hunch: the SystemContextMenu is being closed and opened in a single frame, and the
initStateof the new one is called before thedisposeof the old one. I think that could be possible. The solution may be just to fix that crazy flickering.I will try to investigate this when I have an iPad and Apple Pencil around.
justinmc commentedon Nov 26, 2024
I can reproduce this on a physical iPad and Apple Pencil! The selection menu flicker happens with the Flutter-rendered context menu too, not just SystemContextMenu. I suspect that this flicker is a regression caused by #142463.
PrimaryFeather commentedon Nov 27, 2024
@justinmc Wow, thanks so much for looking into it so swiftly! That pull request seems already like a big improvement. Keep up the great work! 🙌☺️
iPad Scribble flicker and crash (#159508)
jmagman commentedon Dec 2, 2024
Thank you, @justinmc!
justinmc commentedon Dec 4, 2024
Thanks @PrimaryFeather! Let me know if you ever see that error again after upgrading.
github-actions commentedon Dec 18, 2024
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
flutter doctor -vand a minimal reproduction of the issue.