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 {
222
222
/// This is an [AnimatedSwitcherTransitionBuilder] function.
223
223
static Widget defaultTransitionBuilder (Widget child, Animation <double > animation) {
224
224
return FadeTransition (
225
+ key: ValueKey <Key ?>(child.key),
225
226
opacity: animation,
226
227
child: child,
227
228
);
@@ -394,6 +395,6 @@ class _AnimatedSwitcherState extends State<AnimatedSwitcher> with TickerProvider
394
395
@override
395
396
Widget build (BuildContext context) {
396
397
_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 () );
398
399
}
399
400
}
Original file line number Diff line number Diff line change @@ -415,6 +415,25 @@ void main() {
415
415
);
416
416
}
417
417
});
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
+ });
418
437
}
419
438
420
439
class StatefulTest extends StatefulWidget {
You can’t perform that action at this time.
0 commit comments