File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ class AnimatedSwitcher extends StatefulWidget {
222222 /// This is an [AnimatedSwitcherTransitionBuilder] function.
223223 static Widget defaultTransitionBuilder (Widget child, Animation <double > animation) {
224224 return FadeTransition (
225+ key: ValueKey <Key ?>(child.key),
225226 opacity: animation,
226227 child: child,
227228 );
@@ -394,6 +395,6 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
394395 @override
395396 Widget build (BuildContext context) {
396397 _rebuildOutgoingWidgetsIfNeeded ();
397- return widget.layoutBuilder (_currentEntry? .transition, _outgoingWidgets! );
398+ return widget.layoutBuilder (_currentEntry? .transition, _outgoingWidgets! . where (( Widget outgoing) => outgoing.key != _currentEntry ? .transition.key). toSet (). toList () );
398399 }
399400}
Original file line number Diff line number Diff line change @@ -415,6 +415,25 @@ void main() {
415415 );
416416 }
417417 });
418+
419+ testWidgets ('AnimatedSwitcher does not duplicate animations if the same child is entered twice.' , (WidgetTester tester) async {
420+ Future <void > pumpChild (Widget child) async {
421+ return tester.pumpWidget (
422+ Directionality (
423+ textDirection: TextDirection .ltr,
424+ child: AnimatedSwitcher (
425+ duration: const Duration (milliseconds: 1000 ),
426+ child: child,
427+ ),
428+ ),
429+ );
430+ }
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' )));
434+ await tester.pump (const Duration (milliseconds: 1000 ));
435+ expect (find.text ('1' ), findsOneWidget);
436+ });
418437}
419438
420439class StatefulTest extends StatefulWidget {
You can’t perform that action at this time.
0 commit comments