@@ -416,44 +416,23 @@ void main() {
416416 }
417417 });
418418
419- testWidgets ('AnimatedSwitcher can handle multiple children with the same key.' , (WidgetTester tester) async {
420- final UniqueKey containerA = UniqueKey ();
421- final UniqueKey containerB = UniqueKey ();
422-
423- // Pump an AnimatedSwitcher with a child container with the given key.
424- Future <void > pump (Key key) async {
419+ testWidgets ('AnimatedSwitcher does not duplicate animations if the same child is entered twice.' , (WidgetTester tester) async {
420+ Future <void > pumpChild (Widget child) async {
425421 return tester.pumpWidget (
426- AnimatedSwitcher (
427- duration: const Duration (milliseconds: 1000 ),
428- child: Container (key: key),
422+ Directionality (
423+ textDirection: TextDirection .ltr,
424+ child: AnimatedSwitcher (
425+ duration: const Duration (milliseconds: 1000 ),
426+ child: child,
427+ ),
429428 ),
430429 );
431430 }
432-
433- // Pump four widgets with the two keys A and B in alternating order.
434- await pump (containerA );
431+ await pumpChild ( const Text ( '1' , key : Key ( '1' )));
432+ await pumpChild ( const Text ( '2' , key : Key ( '2' )));
433+ await pumpChild ( const Text ( '1' , key : Key ( '1' )) );
435434 await tester.pump (const Duration (milliseconds: 1000 ));
436- await pump (containerB);
437- await tester.pump (const Duration (milliseconds: 500 ));
438- await pump (containerA);
439- await tester.pump (const Duration (milliseconds: 250 ));
440- await pump (containerB);
441- await tester.pump (const Duration (milliseconds: 125 ));
442-
443- // All four widgets should still be animating in (the one pumped last) or
444- // out (the other ones), and thus have an associated FadeTransition each.
445- expect (find.byType (FadeTransition ), findsNWidgets (4 ));
446- final Iterable <FadeTransition > transitions = tester.widgetList (
447- find.byType (FadeTransition ),
448- );
449-
450- // The exponentially decaying timing used in pumping the widgets should have
451- // lined up all of the FadeTransitions' values to be the same.
452- for (final FadeTransition transition in transitions) {
453- expect (transition.opacity.value, moreOrLessEquals (0.125 , epsilon: 0.001 ));
454- }
455-
456- await tester.pumpAndSettle ();
435+ expect (find.text ('1' ), findsOneWidget);
457436 });
458437}
459438
0 commit comments