Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CupertinoContextMenu throws exception on route animation #124785

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/flutter/lib/src/cupertino/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,11 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
if (status != AnimationStatus.dismissed) {
return;
}
setState(() {
_childHidden = false;
});
if (mounted) {
setState(() {
_childHidden = false;
});
}
_route!.animation!.removeStatusListener(_routeAnimationStatusListener);
_route = null;
}
Expand Down
45 changes: 45 additions & 0 deletions packages/flutter/test/cupertino/context_menu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,51 @@ void main() {
expect(tester.getSize(find.byWidget(action)).width, 250);
}
});

testWidgets("ContextMenu route animation doesn't throw exception on dismiss", (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/124597.
final List<int> items = List<int>.generate(2, (int index) => index).toList();

await tester.pumpWidget(CupertinoApp(
home: CupertinoPageScaffold(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return ListView(
children: items.map((int index) => CupertinoContextMenu(
actions: <CupertinoContextMenuAction>[
CupertinoContextMenuAction(
child: const Text('DELETE'),
onPressed: () {
setState(() {
items.remove(index);
Navigator.of(context).pop();
});
Navigator.of(context).pop();
},
),
],
child: Text('Item $index'),
)).toList(),
);
}
),
),
));

// Open the CupertinoContextMenu.
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.text('Item 1')));
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();

// Tap the delete action.
await tester.tap(find.text('DELETE'));
await tester.pumpAndSettle();

// The CupertinoContextMenu should be closed with no exception.
expect(find.text('DELETE'), findsNothing);
expect(tester.takeException(), null);
});
});

group("Open layout differs depending on child's position on screen", () {
Expand Down