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

Fixes https://github.com/flutter/flutter/issues/21445
diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart
index 6a3cd57..811f07f 100644
--- a/packages/flutter/lib/src/material/progress_indicator.dart
+++ b/packages/flutter/lib/src/material/progress_indicator.dart
@@ -374,9 +374,20 @@
   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
diff --git a/packages/flutter/test/material/progress_indicator_test.dart b/packages/flutter/test/material/progress_indicator_test.dart
index 8b2424f..96eb9dd 100644
--- a/packages/flutter/test/material/progress_indicator_test.dart
+++ b/packages/flutter/test/material/progress_indicator_test.dart
@@ -222,7 +222,7 @@
     );
     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 @@
     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);
+  });
 }