Skip to content

Commit 310d47c

Browse files
moepandaQuncCccccc
authored andcommitted
[animations] Add mixed shadow transition tests for OpenContainer
Add coverage for null/non-null shadow combinations in OpenContainer. This verifies the elevation fallback behavior during mixed shadow transitions.
1 parent 2a25d5a commit 310d47c

1 file changed

Lines changed: 190 additions & 0 deletions

File tree

packages/animations/test/open_container_test.dart

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,196 @@ void main() {
455455
expect(openDecoration.shadows, openShadows);
456456
});
457457

458+
testWidgets('Closed elevation transitions into open custom shadows', (
459+
WidgetTester tester,
460+
) async {
461+
const openShadows = <BoxShadow>[
462+
BoxShadow(color: Colors.red, blurRadius: 20.0),
463+
];
464+
465+
await tester.pumpWidget(
466+
_boilerplate(
467+
child: Center(
468+
child: OpenContainer(
469+
closedElevation: 4.0,
470+
openShadows: openShadows,
471+
closedBuilder: (BuildContext context, VoidCallback _) {
472+
return const Text('Closed');
473+
},
474+
openBuilder: (BuildContext context, VoidCallback _) {
475+
return const Text('Open');
476+
},
477+
),
478+
),
479+
),
480+
);
481+
482+
final Element srcMaterialElement = tester.firstElement(
483+
find.ancestor(of: find.text('Closed'), matching: find.byType(Material)),
484+
);
485+
final srcMaterial = srcMaterialElement.widget as Material;
486+
expect(srcMaterial.elevation, 4.0);
487+
expect(
488+
find.ancestor(
489+
of: find.byElementPredicate((Element e) => e == srcMaterialElement),
490+
matching: find.byType(DecoratedBox),
491+
),
492+
findsNothing,
493+
);
494+
495+
await tester.tap(find.text('Closed'));
496+
await tester.pump();
497+
await tester.pump(const Duration(milliseconds: 150));
498+
499+
final Element transitioningMaterialElement = tester.firstElement(
500+
find.ancestor(of: find.text('Closed'), matching: find.byType(Material)),
501+
);
502+
final transitioningMaterial =
503+
transitioningMaterialElement.widget as Material;
504+
expect(transitioningMaterial.elevation, lessThan(4.0));
505+
expect(transitioningMaterial.elevation, greaterThan(0.0));
506+
507+
final Element transitioningDecoratedBoxElement = tester.firstElement(
508+
find.ancestor(
509+
of: find.byElementPredicate(
510+
(Element e) => e == transitioningMaterialElement,
511+
),
512+
matching: find.byType(DecoratedBox),
513+
),
514+
);
515+
final transitioningDecoration =
516+
(transitioningDecoratedBoxElement.widget as DecoratedBox).decoration
517+
as ShapeDecoration;
518+
final double expectedT = Curves.fastOutSlowIn.transform(0.5);
519+
final BoxShadow expectedShadow =
520+
BoxShadow.lerpList(null, openShadows, expectedT)!.single;
521+
expect(transitioningDecoration.shadows, hasLength(1));
522+
expect(transitioningDecoration.shadows![0].color, expectedShadow.color);
523+
expect(
524+
transitioningDecoration.shadows![0].blurRadius,
525+
expectedShadow.blurRadius,
526+
);
527+
expect(
528+
transitioningDecoration.shadows![0].spreadRadius,
529+
expectedShadow.spreadRadius,
530+
);
531+
expect(transitioningDecoration.shadows![0].offset, expectedShadow.offset);
532+
533+
await tester.pumpAndSettle();
534+
535+
final Element openMaterialElement = tester.firstElement(
536+
find.ancestor(of: find.text('Open'), matching: find.byType(Material)),
537+
);
538+
final openMaterial = openMaterialElement.widget as Material;
539+
expect(openMaterial.elevation, 0.0);
540+
541+
final Element openDecoratedBoxElement = tester.firstElement(
542+
find.ancestor(
543+
of: find.byElementPredicate((Element e) => e == openMaterialElement),
544+
matching: find.byType(DecoratedBox),
545+
),
546+
);
547+
final openDecoration =
548+
(openDecoratedBoxElement.widget as DecoratedBox).decoration
549+
as ShapeDecoration;
550+
expect(openDecoration.shadows, openShadows);
551+
});
552+
553+
testWidgets('Closed custom shadows transition into open elevation', (
554+
WidgetTester tester,
555+
) async {
556+
const closedShadows = <BoxShadow>[
557+
BoxShadow(color: Colors.blue, blurRadius: 10.0),
558+
];
559+
560+
await tester.pumpWidget(
561+
_boilerplate(
562+
child: Center(
563+
child: OpenContainer(
564+
closedShadows: closedShadows,
565+
openElevation: 8.0,
566+
closedBuilder: (BuildContext context, VoidCallback _) {
567+
return const Text('Closed');
568+
},
569+
openBuilder: (BuildContext context, VoidCallback _) {
570+
return const Text('Open');
571+
},
572+
),
573+
),
574+
),
575+
);
576+
577+
final Element srcMaterialElement = tester.firstElement(
578+
find.ancestor(of: find.text('Closed'), matching: find.byType(Material)),
579+
);
580+
final srcMaterial = srcMaterialElement.widget as Material;
581+
expect(srcMaterial.elevation, 0.0);
582+
583+
final Element srcDecoratedBoxElement = tester.firstElement(
584+
find.ancestor(
585+
of: find.byElementPredicate((Element e) => e == srcMaterialElement),
586+
matching: find.byType(DecoratedBox),
587+
),
588+
);
589+
final srcDecoration =
590+
(srcDecoratedBoxElement.widget as DecoratedBox).decoration
591+
as ShapeDecoration;
592+
expect(srcDecoration.shadows, closedShadows);
593+
594+
await tester.tap(find.text('Closed'));
595+
await tester.pump();
596+
await tester.pump(const Duration(milliseconds: 150));
597+
598+
final Element transitioningMaterialElement = tester.firstElement(
599+
find.ancestor(of: find.text('Closed'), matching: find.byType(Material)),
600+
);
601+
final transitioningMaterial =
602+
transitioningMaterialElement.widget as Material;
603+
expect(transitioningMaterial.elevation, greaterThan(0.0));
604+
expect(transitioningMaterial.elevation, lessThan(8.0));
605+
606+
final Element transitioningDecoratedBoxElement = tester.firstElement(
607+
find.ancestor(
608+
of: find.byElementPredicate(
609+
(Element e) => e == transitioningMaterialElement,
610+
),
611+
matching: find.byType(DecoratedBox),
612+
),
613+
);
614+
final transitioningDecoration =
615+
(transitioningDecoratedBoxElement.widget as DecoratedBox).decoration
616+
as ShapeDecoration;
617+
final double expectedT = Curves.fastOutSlowIn.transform(0.5);
618+
final BoxShadow expectedShadow =
619+
BoxShadow.lerpList(closedShadows, null, expectedT)!.single;
620+
expect(transitioningDecoration.shadows, hasLength(1));
621+
expect(transitioningDecoration.shadows![0].color, expectedShadow.color);
622+
expect(
623+
transitioningDecoration.shadows![0].blurRadius,
624+
expectedShadow.blurRadius,
625+
);
626+
expect(
627+
transitioningDecoration.shadows![0].spreadRadius,
628+
expectedShadow.spreadRadius,
629+
);
630+
expect(transitioningDecoration.shadows![0].offset, expectedShadow.offset);
631+
632+
await tester.pumpAndSettle();
633+
634+
final Element openMaterialElement = tester.firstElement(
635+
find.ancestor(of: find.text('Open'), matching: find.byType(Material)),
636+
);
637+
final openMaterial = openMaterialElement.widget as Material;
638+
expect(openMaterial.elevation, 8.0);
639+
expect(
640+
find.ancestor(
641+
of: find.byElementPredicate((Element e) => e == openMaterialElement),
642+
matching: find.byType(DecoratedBox),
643+
),
644+
findsNothing,
645+
);
646+
});
647+
458648
testWidgets('Container opens - Fade through', (WidgetTester tester) async {
459649
const ShapeBorder shape = RoundedRectangleBorder(
460650
borderRadius: BorderRadius.all(Radius.circular(8.0)),

0 commit comments

Comments
 (0)