Skip to content

iOS "Scribble" feature: assertion error when using SystemContextMenu #159259

Closed

Description

@PrimaryFeather

Steps to reproduce

  1. Compile and run the code sample from below on an iPad. The sample simply displays a TextField that is using a SystemContextMenu.
  2. Enter some text into the text field.
  3. 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!

Activity

  1. darshankawar commented on Nov 21, 2024

    @darshankawar
    Member

    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.

  2. added
    a: text inputEntering text in a text field or keyboard related problems
    platform-iosiOS applications specifically
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Nov 21, 2024
  3. jmagman commented on Nov 21, 2024

    @jmagman
    Member

    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

  4. justinmc commented on Nov 23, 2024

    @justinmc
    Contributor

    @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.

  5. added
    P2Important issues not at the top of the work list
    on Nov 23, 2024
  6. PrimaryFeather commented on Nov 25, 2024

    @PrimaryFeather
    Author

    @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
  7. justinmc commented on Nov 25, 2024

    @justinmc
    Contributor

    Thank you for the clarification! Ok here's my new hunch: the SystemContextMenu is being closed and opened in a single frame, and the initState of the new one is called before the dispose of 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.

  8. justinmc commented on Nov 26, 2024

    @justinmc
    Contributor

    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.

  9. self-assigned this
    on Nov 26, 2024
  10. PrimaryFeather commented on Nov 27, 2024

    @PrimaryFeather
    Author

    @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! 🙌☺️

  11. jmagman commented on Dec 2, 2024

    @jmagman
    Member

    Thank you, @justinmc!

  12. added
    r: fixedIssue is closed as already fixed in a newer version
    on Dec 3, 2024
  13. justinmc commented on Dec 4, 2024

    @justinmc
    Contributor

    Thanks @PrimaryFeather! Let me know if you ever see that error again after upgrading.

  14. github-actions commented on Dec 18, 2024

    @github-actions

    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 -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsframeworkflutter/packages/flutter repository. See also f: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions