Skip to content

Using CupertinoContextMenu on a widget with onTap can trigger both simultaneously #52226

@MrAlek

Description

@MrAlek

When using CupertinoContextMenu on a widget which also has a GestureDetector with onTap, both the context menu and the other tap action (such as navigating) can be triggered at the same time. See gif:

76107550-2f0acb80-5fd9-11ea-9b90-447cba25d3a7

Code example

CupertinoContextMenu(
  child: GestureDetector(
    onTap: () => Navigator.of(context).pushNamed('/photo'),
    child: Image(image: imageProvider),
  ),
),

Underlying issue

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/cupertino/context_menu.dart#L344-L348

void _onTap() {
    if (_openController.isAnimating && _openController.value < 0.5) {
      _openController.reverse();
    }
  }

If the controller already is opened more than 50%, it doesn't close. Since there's no way of detecting this from the other gesture detector, both are triggered.

Proposed solution

Always reverse the context menu onTap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: cupertinoflutter/packages/flutter/cupertino repositoryf: gesturesflutter/packages/flutter/gestures repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions