Unverified Commit 6f435b28 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Stop the animation controller if a CircularProgressIndicator is determinate (#21832)

Fixes https://github.com/flutter/flutter/issues/21445
parent 2bca8007
......@@ -374,9 +374,20 @@ class _CircularProgressIndicatorState extends State<CircularProgressIndicator> w
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 6666),
duration: const Duration(seconds: 5),
vsync: this,
)..repeat();
);
if (widget.value == null)
_controller.repeat();
}
@override
void didUpdateWidget(CircularProgressIndicator oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.value == null && !_controller.isAnimating)
_controller.repeat();
else if (widget.value != null && _controller.isAnimating)
_controller.stop();
}
@override
......
......@@ -222,7 +222,7 @@ void main() {
);
expect(tester.hasRunningAnimations, isTrue);
await tester.pump(const Duration(milliseconds: 6666));
await tester.pump(const Duration(seconds: 5));
expect(tester.hasRunningAnimations, isTrue);
await tester.pump(const Duration(milliseconds: 1));
......@@ -232,4 +232,27 @@ void main() {
expect(tester.hasRunningAnimations, isTrue);
});
testWidgets('Determinate CircularProgressIndicator stops the animator', (WidgetTester tester) async {
double progressValue;
StateSetter setState;
await tester.pumpWidget(
Center(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setter) {
setState = setter;
return CircularProgressIndicator(value: progressValue);
}
),
)
);
expect(tester.hasRunningAnimations, isTrue);
setState(() { progressValue = 1.0; });
await tester.pump(const Duration(milliseconds: 1));
expect(tester.hasRunningAnimations, isFalse);
setState(() { progressValue = null; });
await tester.pump(const Duration(milliseconds: 1));
expect(tester.hasRunningAnimations, isTrue);
});
}
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