Stop the animation controller if a CircularProgressIndicator is determinate (#21832)
Fixes https://github.com/flutter/flutter/issues/21445
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user