diff --git a/packages/flutter/lib/src/cupertino/context_menu.dart b/packages/flutter/lib/src/cupertino/context_menu.dart index 1240803909c96c..a9ddd25bc939b0 100644 --- a/packages/flutter/lib/src/cupertino/context_menu.dart +++ b/packages/flutter/lib/src/cupertino/context_menu.dart @@ -172,11 +172,9 @@ class CupertinoContextMenu extends StatefulWidget { /// /// final Animation boxDecorationAnimation = DecorationTween( /// begin: const BoxDecoration( - /// color: Color(0xFFFFFFFF), /// boxShadow: [], /// ), /// end: const BoxDecoration( - /// color: Color(0xFFFFFFFF), /// boxShadow: CupertinoContextMenu.kEndBoxShadow, /// ), /// ).animate( @@ -279,11 +277,9 @@ class CupertinoContextMenu extends StatefulWidget { /// /// final Animation boxDecorationAnimation = DecorationTween( /// begin: const BoxDecoration( - /// color: Color(0xFFFFFFFF), /// boxShadow: [], /// ), /// end: const BoxDecoration( - /// color: Color(0xFFFFFFFF), /// boxShadow: CupertinoContextMenu.kEndBoxShadow, /// ), /// ).animate( @@ -676,11 +672,9 @@ class _DecoyChildState extends State<_DecoyChild> with TickerProviderStateMixin _boxDecoration = DecorationTween( begin: const BoxDecoration( - color: Color(0xFFFFFFFF), boxShadow: [], ), end: const BoxDecoration( - color: Color(0xFFFFFFFF), boxShadow: _endBoxShadow, ), ).animate(CurvedAnimation( diff --git a/packages/flutter/test/cupertino/context_menu_test.dart b/packages/flutter/test/cupertino/context_menu_test.dart index bc1dd8bd56b11f..08a1f74f958d58 100644 --- a/packages/flutter/test/cupertino/context_menu_test.dart +++ b/packages/flutter/test/cupertino/context_menu_test.dart @@ -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( + 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 expectedColors = [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 animation) {