flutter-quill icon indicating copy to clipboard operation
flutter-quill copied to clipboard

Back Button Fails to Dismiss Context Menu Toolbar on Android

Open EchoEllet opened this issue 8 months ago • 2 comments

Have you checked for an existing issue?

Flutter Quill Version

11.2.0

Steps to Reproduce

  1. Run on a real Android device and select some text.
  2. Once the context menu (AKA toolbar) is shown, press the back button
  3. The context menu is being ignored without dismissing it; it could lead to navigating back to the previous screen or closing the app.

Expected results

The toolbar should be dismissed instead. I don't remember this was an issue before, and I'm not sure which change made this regression.

Actual results

The context menu is still being displayed, and instead, the back button dismisses the keyboard or navigates back to the previous screen, or closes the app.

See the attached video for details.

Additional Context

Screenshots / Video demonstration

Current behavior:

https://github.com/user-attachments/assets/aa132450-83dd-4894-aa94-ee8243034d31

Expected behavior (Keep notes app as an example):

https://github.com/user-attachments/assets/9a8dc1f0-4017-45ad-a9d6-a8510f0fafc9

EchoEllet avatar Mar 27 '25 16:03 EchoEllet

As a temporary fix until an official patch lands, you can wrap your QuillEditor in a WillPopScope that first checks if the editor is focused, unfocuses it (which dismisses the toolbar), and only allows back navigation when the editor is already unfocused. Wrap your QuillEditor in a WillPopScope that unfocuses the editor (hiding the toolbar) before popping the route:

WillPopScope(
  onWillPop: () async {
    if (_focusNode.hasFocus) {
      _focusNode.unfocus();
      return false;
    }
    return true;
  },
  child: QuillEditor(
    controller: _controller,
    focusNode: _focusNode,
    scrollController: ScrollController(),
    scrollable: true,
    padding: EdgeInsets.all(8),
    autoFocus: false,
    readOnly: false,
    expands: false,
  ),
)

This makes the first Back-press hide the toolbar and only subsequent presses navigate back.

shafisma avatar Apr 27 '25 16:04 shafisma

if (_focusNode.hasFocus) { _focusNode.unfocus(); return false; } return true;

This is an Android specific issue. You might want to test this workaround on other platforms in addition to testing it on an Android emulator and apply it only when necessary. You should probably link this issue in a comment explaining the workaround. If a fix arrives, it will silently break the behavior without notice.

EchoEllet avatar Apr 27 '25 17:04 EchoEllet