Skip to content

Conversation

@ahmedsameha1
Copy link
Contributor

This is my attempt to handle #6537 for the CupertinoContextMenu widget.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Nov 18, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to fix a crash in CupertinoContextMenu when it has a zero size. A test case has been added to reproduce this scenario. However, the test does not seem to trigger the crash condition as it doesn't simulate opening the context menu. Additionally, the fix for the underlying division-by-zero issue appears to be missing from this pull request. I've suggested an update to the test to correctly validate the fix.

Comment on lines +1544 to +1558
testWidgets('CupertinoContextMenu does not crash at zero area', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox.shrink(
child: CupertinoContextMenu(
actions: const <Widget>[Text('X'), Text('Y')],
child: const Text('Y'),
),
),
),
),
);
expect(tester.getSize(find.byType(CupertinoContextMenu)), Size.zero);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This test doesn't fully cover the scenario described in the issue. The crash occurs when the context menu is opened via a long press, but this test only verifies that the widget can be pumped without crashing. To ensure the fix is effective, the test should also simulate opening the context menu, which would trigger the code path that causes the division-by-zero error.1

  testWidgets('CupertinoContextMenu does not crash at zero area', (WidgetTester tester) async {
    await tester.pumpWidget(
      CupertinoApp(
        home: Center(
          child: SizedBox.shrink(
            child: CupertinoContextMenu(
              actions: const <Widget>[Text('X'), Text('Y')],
              child: const Text('Y'),
            ),
          ),
        ),
      ),
    );
    expect(tester.getSize(find.byType(CupertinoContextMenu)), Size.zero);

    // Trigger the context menu to ensure it doesn't crash.
    await tester.longPress(find.byType(CupertinoContextMenu));
    await tester.pump(); // Let animations start.
    // The test passes if it doesn't crash.
  });

Style Guide References

Footnotes

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, the context menu is activated when its child is long pressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applying this produces:
Finder specifies a widget that would not receive pointer events.
A call to longPress() with finder "Found 1 widget with type "CupertinoContextMenu": [
CupertinoContextMenu(state: _CupertinoContextMenuState#6f93c(tickers: tracking 1 ticker)),
]" derived an Offset (Offset(400.0, 300.0)) that would not hit test on the specified widget.
Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot
receive pointer events.

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

Although this widget is basically an overlay, I think it has no way to open programatically and thus we can't test the overlay at zero area.

Comment on lines +1544 to +1558
testWidgets('CupertinoContextMenu does not crash at zero area', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: SizedBox.shrink(
child: CupertinoContextMenu(
actions: const <Widget>[Text('X'), Text('Y')],
child: const Text('Y'),
),
),
),
),
);
expect(tester.getSize(find.byType(CupertinoContextMenu)), Size.zero);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, the context menu is activated when its child is long pressed.

version: "2.2.2"
sdks:
dart: ">=3.9.0 <4.0.0"
dart: ">=3.11.0-88.0.dev <4.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be reverted?

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 22, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Nov 22, 2025
Merged via the queue into flutter:master with commit c213a54 Nov 22, 2025
71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 22, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 22, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 22, 2025
flutter/flutter@d438df3...c8cfb2b

2025-11-22 [email protected] Revert "[ios] Dynamic Content Resizing" (flutter/flutter#178958)
2025-11-22 [email protected] Make sure that a SearchAnchor doesn't crash in 0x0 environment (flutter/flutter#177749)
2025-11-22 [email protected] Make sure that a Stepper doesn't crash in 0x0 environment (flutter/flutter#178068)
2025-11-22 [email protected] Remove deprecated `activeColor` in `switch.0.dart` example (flutter/flutter#178293)
2025-11-22 [email protected] Make sure that a UserAccountsDrawerHeader doesn't crash in 0x0 enviro… (flutter/flutter#178516)
2025-11-22 [email protected] Make sure that a TimePickerDialog doesn't crash in 0x0 environment (flutter/flutter#178451)
2025-11-22 [email protected] Make sure that a CupertinoLinearActivityIndicator doesn't crash in 0x… (flutter/flutter#178566)
2025-11-22 [email protected] Make sure that a CupertinoTabBar doesn't crash in 0x0 environment (flutter/flutter#178613)
2025-11-22 [email protected] Make sure that a CupertinoContextMenu doesn't crash in 0x0 environment (flutter/flutter#178722)
2025-11-22 [email protected] Sort entries in TESTOWNERS (flutter/flutter#178939)
2025-11-22 [email protected] [ios] Dynamic Content Resizing (flutter/flutter#177410)
2025-11-21 [email protected] Roll Skia from dc88b21ce7d2 to 3018c3053490 (2 revisions) (flutter/flutter#178947)
2025-11-21 [email protected] Manually roll material_color_utilities (flutter/flutter#170000)
2025-11-21 [email protected] Roll Fuchsia Linux SDK from Y-cMdgKy3d6EnibWR... to 4ul9jvZ7jnDGIjtCD... (flutter/flutter#178934)
2025-11-21 [email protected] Roll Dart SDK from c788b6a7aefd to 5af71c736b0a (1 revision) (flutter/flutter#178932)
2025-11-21 [email protected] Roll Skia from c588bb60d5da to dc88b21ce7d2 (2 revisions) (flutter/flutter#178933)
2025-11-21 [email protected] Update .ci.yaml and TESTOWNERS for arc macrobenchmark tests (flutter/flutter#178891)
2025-11-21 [email protected] Use interactive mode with `devicectl` to redirect stdout (flutter/flutter#178405)
2025-11-21 [email protected] Update .ci.yaml in flutter/flutter to use either macOS 15.5 or macOS … (flutter/flutter#178666)
2025-11-21 [email protected] Roll Skia from d4e9d2873bfd to c588bb60d5da (1 revision) (flutter/flutter#178928)
2025-11-21 [email protected] Roll Packages from b1e2fb0 to e67b6be (7 revisions) (flutter/flutter#178927)

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 [email protected],[email protected] 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
mboetger pushed a commit to mboetger/flutter that referenced this pull request Dec 2, 2025
flutter#178722)

This is my attempt to handle
flutter#6537 for the
CupertinoContextMenu widget.
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
flutter#178722)

This is my attempt to handle
flutter#6537 for the
CupertinoContextMenu widget.
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.

3 participants