Skip to content

Commit

Permalink
Fix Cupertino Context Menu Container to Remove White Corners (flutter…
Browse files Browse the repository at this point in the history
…#144883)

Fixes a visual glitch when CupertinoContextMenu is on a non-white background.
  • Loading branch information
dhikshith12 committed Mar 13, 2024
1 parent 1228493 commit f91614a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
6 changes: 0 additions & 6 deletions packages/flutter/lib/src/cupertino/context_menu.dart
Expand Up @@ -172,11 +172,9 @@ class CupertinoContextMenu extends StatefulWidget {
///
/// final Animation<Decoration> boxDecorationAnimation = DecorationTween(
/// begin: const BoxDecoration(
/// color: Color(0xFFFFFFFF),
/// boxShadow: <BoxShadow>[],
/// ),
/// end: const BoxDecoration(
/// color: Color(0xFFFFFFFF),
/// boxShadow: CupertinoContextMenu.kEndBoxShadow,
/// ),
/// ).animate(
Expand Down Expand Up @@ -279,11 +277,9 @@ class CupertinoContextMenu extends StatefulWidget {
///
/// final Animation<Decoration> boxDecorationAnimation = DecorationTween(
/// begin: const BoxDecoration(
/// color: Color(0xFFFFFFFF),
/// boxShadow: <BoxShadow>[],
/// ),
/// end: const BoxDecoration(
/// color: Color(0xFFFFFFFF),
/// boxShadow: CupertinoContextMenu.kEndBoxShadow,
/// ),
/// ).animate(
Expand Down Expand Up @@ -676,11 +672,9 @@ class _DecoyChildState extends State<_DecoyChild> with TickerProviderStateMixin

_boxDecoration = DecorationTween(
begin: const BoxDecoration(
color: Color(0xFFFFFFFF),
boxShadow: <BoxShadow>[],
),
end: const BoxDecoration(
color: Color(0xFFFFFFFF),
boxShadow: _endBoxShadow,
),
).animate(CurvedAnimation(
Expand Down
55 changes: 55 additions & 0 deletions packages/flutter/test/cupertino/context_menu_test.dart
Expand Up @@ -241,6 +241,61 @@ void main() {
expect(findStatic(), findsOneWidget);
});

testWidgets('_DecoyChild preserves the child color', (WidgetTester tester) async {
final Widget child = getChild();
await tester.pumpWidget(CupertinoApp(
home: CupertinoPageScaffold(
backgroundColor: CupertinoColors.black,
child: MediaQuery(
data: const MediaQueryData(size: Size(800, 600)),
child: Center(
child: CupertinoContextMenu(
actions: const <CupertinoContextMenuAction>[
CupertinoContextMenuAction(
child: Text('CupertinoContextMenuAction'),
),
],
child: child
),
)
)
),
));

// Expect no _DecoyChild to be present before the gesture.
final Finder decoyChild = find
.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DecoyChild');
expect(decoyChild, findsNothing);

// Start press gesture on the child.
final Rect childRect = tester.getRect(find.byWidget(child));
final TestGesture gesture = await tester.startGesture(childRect.center);
await tester.pump();

// Find the _DecoyChild by runtimeType,
// find the Container descendant with the BoxDecoration,
// then read the boxDecoration property.
final Finder decoyChildDescendant = find.descendant(
of: decoyChild,
matching: find.byType(Container));
final BoxDecoration? boxDecoration = (tester.firstWidget(decoyChildDescendant) as Container).decoration as BoxDecoration?;
const List<Color?> expectedColors = <Color?>[null, Color(0x00000000)];

// `Color(0x00000000)` -> Is `Colors.transparent`.
// `null` -> Default when no color argument is given in `BoxDecoration`.
// Any other color won't preserve the child's property.
expect(expectedColors, contains(boxDecoration?.color));

// End the gesture.
await gesture.up();
await tester.pumpAndSettle();

// Expect no _DecoyChild to be present after ending the gesture.
final Finder decoyChildAfterEnding = find
.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DecoyChild');
expect(decoyChildAfterEnding, findsNothing);
});

testWidgets('CupertinoContextMenu with a basic builder opens and closes the same as when providing a child', (WidgetTester tester) async {
final Widget child = getChild();
await tester.pumpWidget(getBuilderContextMenu(builder: (BuildContext context, Animation<double> animation) {
Expand Down

0 comments on commit f91614a

Please sign in to comment.