Unverified Commit 64a28e36 authored by rami-a's avatar rami-a Committed by GitHub

Fix issue with account drawer header arrow rotating when setState is called (#29980)

The UserAccountsDrawerHeader had a bug with the arrow rotating whenever setState was called on its parent. This change makes sure that we check that the state actually changed before allowing the animation to trigger.

Fixes #25801
parent bafe7cbb
...@@ -113,8 +113,12 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi ...@@ -113,8 +113,12 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
@override @override
void didUpdateWidget (_AccountDetails oldWidget) { void didUpdateWidget (_AccountDetails oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (_animation.status == AnimationStatus.dismissed || // If the state of the arrow did not change, there is no need to trigger the animation
_animation.status == AnimationStatus.reverse) { if (oldWidget.isOpen == widget.isOpen) {
return;
}
if (widget.isOpen) {
_controller.forward(); _controller.forward();
} else { } else {
_controller.reverse(); _controller.reverse();
......
...@@ -139,6 +139,42 @@ void main() { ...@@ -139,6 +139,42 @@ void main() {
expect(transformWidget.transform.getRotation()[4], 1.0); expect(transformWidget.transform.getRotation()[4], 1.0);
}); });
// Regression test for https://github.com/flutter/flutter/issues/25801.
testWidgets('UserAccountsDrawerHeader icon does not rotate after setState', (WidgetTester tester) async {
StateSetter testSetState;
await tester.pumpWidget(MaterialApp(
home: Material(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
testSetState = setState;
return UserAccountsDrawerHeader(
onDetailsPressed: () { },
accountName: const Text('name'),
accountEmail: const Text('email'),
);
},
),
),
));
Transform transformWidget = tester.firstWidget(find.byType(Transform));
// Icon is right side up.
expect(transformWidget.transform.getRotation()[0], 1.0);
expect(transformWidget.transform.getRotation()[4], 1.0);
testSetState(() { });
await tester.pump(const Duration(milliseconds: 10));
expect(tester.hasRunningAnimations, isFalse);
await tester.pumpAndSettle();
transformWidget = tester.firstWidget(find.byType(Transform));
// Icon has not rotated.
expect(transformWidget.transform.getRotation()[0], 1.0);
expect(transformWidget.transform.getRotation()[4], 1.0);
});
testWidgets('UserAccountsDrawerHeader icon rotation test speeeeeedy', (WidgetTester tester) async { testWidgets('UserAccountsDrawerHeader icon rotation test speeeeeedy', (WidgetTester tester) async {
await pumpTestWidget(tester); await pumpTestWidget(tester);
Transform transformWidget = tester.firstWidget(find.byType(Transform)); Transform transformWidget = tester.firstWidget(find.byType(Transform));
......
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