Skip to content

Conversation

victorsanni
Copy link
Contributor

@victorsanni victorsanni commented Jun 6, 2025

Fixes CupertinoContextMenu potential unremoved overlay entry
Fixes CupertinoContextMenu onTap gesture interferes with child widget with onTap GestureRecognizer

Sample code
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

bool ctxMenuRemoved = false;

class ContextMenuApp extends StatelessWidget {
  const ContextMenuApp({super.key});

  @override
  Widget build(BuildContext context) {
    final colorScheme = ColorScheme.fromSeed(seedColor: Colors.orange);
    return MaterialApp(
      theme: ThemeData(
        colorScheme: colorScheme,
        appBarTheme:
            AppBarTheme(backgroundColor: colorScheme.secondaryContainer),
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: Text('Home'),
        ),
        body: Center(
          child: CupertinoContextMenu(
            actions: [
              CupertinoContextMenuAction(
                child: Text('Test'),
              ),
            ],
            child: GestureDetector(
              onTap: () {
                Navigator.of(context).push(
                  MaterialPageRoute(builder: (context) => _OtherPage()),
                );
              },
              child: Container(
                color: Colors.orange,
                height: 100,
                width: 100,
              ),
            ),
          ),
        ),
      );
}

class _OtherPage extends StatelessWidget {
  const _OtherPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Align(
        child: Builder(builder: (context) {
          return Listener(
            onPointerDown: (_) {
              Timer(const Duration(milliseconds: 480), () {
                ctxMenuRemoved = true;
                (context as Element).markNeedsBuild();
              });
            },
            child: ctxMenuRemoved
                ? const SizedBox()
                : CupertinoContextMenu(
                    actions: [
                      CupertinoContextMenuAction(
                        child: const Text('Action one'),
                        onPressed: () {},
                      ),
                    ],
                    child: Container(
                      height: 100,
                      width: 100,
                      color: Colors.black45,
                    ),
                  ),
          );
        }),
      ),
    );
  }
}

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@victorsanni victorsanni marked this pull request as draft June 6, 2025 23:13
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Jun 6, 2025
@victorsanni victorsanni marked this pull request as ready for review June 11, 2025 01:34
@victorsanni victorsanni changed the title Close context menu if route is pushed mid-animation Close CupertinoContextMenu overlay if the widget is disposed or a new route is pushed Jun 11, 2025
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍


// Kickstart the route transition.
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this duration dependent on the duration of the route transition? FYI I am working on figuring out a way to dynamically get this value in tests, see #165832 (comment). Probably no action to take on this PR, but just a heads up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but 👍

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 20, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 20, 2025
Merged via the queue into flutter:master with commit be8cdeb Jun 20, 2025
76 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 21, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 22, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 23, 2025
flutter/flutter@c7362b4...0ab008a

2025-06-22 engine-flutter-autoroll@skia.org Roll Skia from 203469ef4672 to fcd1c55da9cc (1 revision) (flutter/flutter#170986)
2025-06-22 engine-flutter-autoroll@skia.org Roll Dart SDK from e5db5e0f81ba to 98db1db5ff65 (2 revisions) (flutter/flutter#170979)
2025-06-21 bruno.leroux@gmail.com Normalize input decoration theme (flutter/flutter#168981)
2025-06-21 engine-flutter-autoroll@skia.org Roll Skia from dceb857b1c47 to 203469ef4672 (1 revision) (flutter/flutter#170959)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from 6325aeacaef4 to e5db5e0f81ba (1 revision) (flutter/flutter#170958)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from a6a3d65e33d7 to 6325aeacaef4 (2 revisions) (flutter/flutter#170955)
2025-06-21 engine-flutter-autoroll@skia.org Roll Skia from 773188560221 to dceb857b1c47 (1 revision) (flutter/flutter#170954)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from 750eaa028445 to a6a3d65e33d7 (1 revision) (flutter/flutter#170953)
2025-06-21 hidea@users.noreply.github.com Fix the Japanese IME problem on macOS reported in the following issue. (flutter/flutter#166291)
2025-06-21 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from IfPORaYjQ2zP4bcq-... to 2wEtX_lDNhHhDNsP6... (flutter/flutter#170946)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 104460420c48 to 773188560221 (2 revisions) (flutter/flutter#170942)
2025-06-20 huy@nevercode.io Normalize AppBarTheme (flutter/flutter#169130)
2025-06-20 victorsanniay@gmail.com Close CupertinoContextMenu overlay if the widget is disposed or a new route is pushed (flutter/flutter#170186)
2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from a554bdd0a2cc to 750eaa028445 (1 revision) (flutter/flutter#170933)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from b638003de37e to 104460420c48 (1 revision) (flutter/flutter#170932)
2025-06-20 engine-flutter-autoroll@skia.org Roll Packages from 0ec4053 to 7f41e75 (1 revision) (flutter/flutter#170925)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from f1e68950ea7b to b638003de37e (5 revisions) (flutter/flutter#170923)
2025-06-20 30870216+gaaclarke@users.noreply.github.com [licenses_cpp] jun17 (flutter/flutter#170845)

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 stuartmorgan@google.com 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
Ortes pushed a commit to Ortes/packages that referenced this pull request Jun 25, 2025
…r#9472)

flutter/flutter@c7362b4...0ab008a

2025-06-22 engine-flutter-autoroll@skia.org Roll Skia from 203469ef4672 to fcd1c55da9cc (1 revision) (flutter/flutter#170986)
2025-06-22 engine-flutter-autoroll@skia.org Roll Dart SDK from e5db5e0f81ba to 98db1db5ff65 (2 revisions) (flutter/flutter#170979)
2025-06-21 bruno.leroux@gmail.com Normalize input decoration theme (flutter/flutter#168981)
2025-06-21 engine-flutter-autoroll@skia.org Roll Skia from dceb857b1c47 to 203469ef4672 (1 revision) (flutter/flutter#170959)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from 6325aeacaef4 to e5db5e0f81ba (1 revision) (flutter/flutter#170958)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from a6a3d65e33d7 to 6325aeacaef4 (2 revisions) (flutter/flutter#170955)
2025-06-21 engine-flutter-autoroll@skia.org Roll Skia from 773188560221 to dceb857b1c47 (1 revision) (flutter/flutter#170954)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from 750eaa028445 to a6a3d65e33d7 (1 revision) (flutter/flutter#170953)
2025-06-21 hidea@users.noreply.github.com Fix the Japanese IME problem on macOS reported in the following issue. (flutter/flutter#166291)
2025-06-21 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from IfPORaYjQ2zP4bcq-... to 2wEtX_lDNhHhDNsP6... (flutter/flutter#170946)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 104460420c48 to 773188560221 (2 revisions) (flutter/flutter#170942)
2025-06-20 huy@nevercode.io Normalize AppBarTheme (flutter/flutter#169130)
2025-06-20 victorsanniay@gmail.com Close CupertinoContextMenu overlay if the widget is disposed or a new route is pushed (flutter/flutter#170186)
2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from a554bdd0a2cc to 750eaa028445 (1 revision) (flutter/flutter#170933)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from b638003de37e to 104460420c48 (1 revision) (flutter/flutter#170932)
2025-06-20 engine-flutter-autoroll@skia.org Roll Packages from 0ec4053 to 7f41e75 (1 revision) (flutter/flutter#170925)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from f1e68950ea7b to b638003de37e (5 revisions) (flutter/flutter#170923)
2025-06-20 30870216+gaaclarke@users.noreply.github.com [licenses_cpp] jun17 (flutter/flutter#170845)

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 stuartmorgan@google.com 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
@victorsanni victorsanni deleted the context-menu-overlay branch July 1, 2025 19:59
mboetger pushed a commit to mboetger/flutter that referenced this pull request Jul 21, 2025
… route is pushed (flutter#170186)

Fixes [CupertinoContextMenu potential unremoved overlay
entry](flutter#131471)
Fixes [CupertinoContextMenu onTap gesture interferes with child widget
with onTap
GestureRecognizer](flutter#169911)

<details>
<summary>Sample code</summary>

```dart

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

bool ctxMenuRemoved = false;

class ContextMenuApp extends StatelessWidget {
  const ContextMenuApp({super.key});

  @OverRide
  Widget build(BuildContext context) {
    final colorScheme = ColorScheme.fromSeed(seedColor: Colors.orange);
    return MaterialApp(
      theme: ThemeData(
        colorScheme: colorScheme,
        appBarTheme:
            AppBarTheme(backgroundColor: colorScheme.secondaryContainer),
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @OverRide
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: Text('Home'),
        ),
        body: Center(
          child: CupertinoContextMenu(
            actions: [
              CupertinoContextMenuAction(
                child: Text('Test'),
              ),
            ],
            child: GestureDetector(
              onTap: () {
                Navigator.of(context).push(
                  MaterialPageRoute(builder: (context) => _OtherPage()),
                );
              },
              child: Container(
                color: Colors.orange,
                height: 100,
                width: 100,
              ),
            ),
          ),
        ),
      );
}

class _OtherPage extends StatelessWidget {
  const _OtherPage({super.key});

  @OverRide
  Widget build(BuildContext context) {
    return Scaffold(
      body: Align(
        child: Builder(builder: (context) {
          return Listener(
            onPointerDown: (_) {
              Timer(const Duration(milliseconds: 480), () {
                ctxMenuRemoved = true;
                (context as Element).markNeedsBuild();
              });
            },
            child: ctxMenuRemoved
                ? const SizedBox()
                : CupertinoContextMenu(
                    actions: [
                      CupertinoContextMenuAction(
                        child: const Text('Action one'),
                        onPressed: () {},
                      ),
                    ],
                    child: Container(
                      height: 100,
                      width: 100,
                      color: Colors.black45,
                    ),
                  ),
          );
        }),
      ),
    );
  }
}


```

</details>
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
…r#9472)

flutter/flutter@c7362b4...0ab008a

2025-06-22 engine-flutter-autoroll@skia.org Roll Skia from 203469ef4672 to fcd1c55da9cc (1 revision) (flutter/flutter#170986)
2025-06-22 engine-flutter-autoroll@skia.org Roll Dart SDK from e5db5e0f81ba to 98db1db5ff65 (2 revisions) (flutter/flutter#170979)
2025-06-21 bruno.leroux@gmail.com Normalize input decoration theme (flutter/flutter#168981)
2025-06-21 engine-flutter-autoroll@skia.org Roll Skia from dceb857b1c47 to 203469ef4672 (1 revision) (flutter/flutter#170959)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from 6325aeacaef4 to e5db5e0f81ba (1 revision) (flutter/flutter#170958)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from a6a3d65e33d7 to 6325aeacaef4 (2 revisions) (flutter/flutter#170955)
2025-06-21 engine-flutter-autoroll@skia.org Roll Skia from 773188560221 to dceb857b1c47 (1 revision) (flutter/flutter#170954)
2025-06-21 engine-flutter-autoroll@skia.org Roll Dart SDK from 750eaa028445 to a6a3d65e33d7 (1 revision) (flutter/flutter#170953)
2025-06-21 hidea@users.noreply.github.com Fix the Japanese IME problem on macOS reported in the following issue. (flutter/flutter#166291)
2025-06-21 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from IfPORaYjQ2zP4bcq-... to 2wEtX_lDNhHhDNsP6... (flutter/flutter#170946)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 104460420c48 to 773188560221 (2 revisions) (flutter/flutter#170942)
2025-06-20 huy@nevercode.io Normalize AppBarTheme (flutter/flutter#169130)
2025-06-20 victorsanniay@gmail.com Close CupertinoContextMenu overlay if the widget is disposed or a new route is pushed (flutter/flutter#170186)
2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from a554bdd0a2cc to 750eaa028445 (1 revision) (flutter/flutter#170933)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from b638003de37e to 104460420c48 (1 revision) (flutter/flutter#170932)
2025-06-20 engine-flutter-autoroll@skia.org Roll Packages from 0ec4053 to 7f41e75 (1 revision) (flutter/flutter#170925)
2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from f1e68950ea7b to b638003de37e (5 revisions) (flutter/flutter#170923)
2025-06-20 30870216+gaaclarke@users.noreply.github.com [licenses_cpp] jun17 (flutter/flutter#170845)

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 stuartmorgan@google.com 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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CupertinoContextMenu onTap gesture interferes with child widget with onTap GestureRecognizer [CupertinoContextMenu] Potential unremoved overlay entry
2 participants