Unverified Commit 874df1ec authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix bug in AnimatedSwitcher (#22183)

* Refactor AnimatedSwitcher

This is mostly just a little bit of cleanup with hopefully no semantic
changes, done to teach me how the code works so that I could fix a bug.

* Add debugging information to AnimatedSwitcher

* Fix AnimatedSwitcher to handle the case of back-to-back changes

Previously, if a child was replaced the very next frame after it was
added, we'd get confused because we tried to reverse the controller,
which causes us to remove the child from the going-away list, before
we had added the child to the list in the first place.

The fix is just to move the reverse to after the add.
parent 8d643013
......@@ -56,6 +56,47 @@ void main() {
await tester.pumpAndSettle();
});
testWidgets('AnimatedSwitcher can handle back-to-back changes.', (WidgetTester tester) async {
final UniqueKey container1 = UniqueKey();
final UniqueKey container2 = UniqueKey();
final UniqueKey container3 = UniqueKey();
await tester.pumpWidget(
AnimatedSwitcher(
duration: const Duration(milliseconds: 100),
child: Container(key: container1),
switchInCurve: Curves.linear,
switchOutCurve: Curves.linear,
),
);
expect(find.byKey(container1), findsOneWidget);
expect(find.byKey(container2), findsNothing);
expect(find.byKey(container3), findsNothing);
await tester.pumpWidget(
AnimatedSwitcher(
duration: const Duration(milliseconds: 100),
child: Container(key: container2),
switchInCurve: Curves.linear,
switchOutCurve: Curves.linear,
),
);
expect(find.byKey(container1), findsOneWidget);
expect(find.byKey(container2), findsOneWidget);
expect(find.byKey(container3), findsNothing);
await tester.pumpWidget(
AnimatedSwitcher(
duration: const Duration(milliseconds: 100),
child: Container(key: container3),
switchInCurve: Curves.linear,
switchOutCurve: Curves.linear,
),
);
expect(find.byKey(container1), findsOneWidget);
expect(find.byKey(container2), findsNothing);
expect(find.byKey(container3), findsOneWidget);
});
testWidgets("AnimatedSwitcher doesn't transition in a new child of the same type.", (WidgetTester tester) async {
await tester.pumpWidget(
AnimatedSwitcher(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment