diff --git a/packages/flutter/lib/src/cupertino/activity_indicator.dart b/packages/flutter/lib/src/cupertino/activity_indicator.dart index 2efd97a107..263271058f 100644 --- a/packages/flutter/lib/src/cupertino/activity_indicator.dart +++ b/packages/flutter/lib/src/cupertino/activity_indicator.dart @@ -27,6 +27,7 @@ class CupertinoActivityIndicator extends StatefulWidget { /// Creates an iOS-style activity indicator that spins clockwise. const CupertinoActivityIndicator({ Key? key, + this.color, this.animating = true, this.radius = _kDefaultIndicatorRadius, }) : assert(animating != null), @@ -43,6 +44,7 @@ class CupertinoActivityIndicator extends StatefulWidget { /// to 1.0. const CupertinoActivityIndicator.partiallyRevealed({ Key? key, + this.color, this.radius = _kDefaultIndicatorRadius, this.progress = 1.0, }) : assert(radius != null), @@ -53,6 +55,11 @@ class CupertinoActivityIndicator extends StatefulWidget { animating = false, super(key: key); + /// Color of the activity indicator. + /// + /// Defaults to color extracted from native iOS. + final Color? color; + /// Whether the activity indicator is running its animation. /// /// Defaults to true. @@ -117,8 +124,7 @@ class _CupertinoActivityIndicatorState extends State child: CustomPaint( painter: _CupertinoActivityIndicatorPainter( position: _controller, - activeColor: - CupertinoDynamicColor.resolve(_kActiveTickColor, context), + activeColor: widget.color ?? CupertinoDynamicColor.resolve(_kActiveTickColor, context), radius: widget.radius, progress: widget.progress, ), diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 925bd6f0d9..ccff5367f7 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -594,7 +594,8 @@ class _CircularProgressIndicatorState extends State w } Widget _buildCupertinoIndicator(BuildContext context) { - return CupertinoActivityIndicator(key: widget.key); + final Color? tickColor = widget.backgroundColor; + return CupertinoActivityIndicator(key: widget.key, color: tickColor); } Widget _buildMaterialIndicator(BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) { diff --git a/packages/flutter/test/cupertino/activity_indicator_test.dart b/packages/flutter/test/cupertino/activity_indicator_test.dart index 4ea3902cad..9d19ab177c 100644 --- a/packages/flutter/test/cupertino/activity_indicator_test.dart +++ b/packages/flutter/test/cupertino/activity_indicator_test.dart @@ -158,6 +158,32 @@ void main() { ..rrect(rrect: const RRect.fromLTRBXY(-10, -100 / 3, 10, -100, 10, 10)), ); }); + + testWidgets('Can specify color', (WidgetTester tester) async { + final Key key = UniqueKey(); + await tester.pumpWidget( + Center( + child: RepaintBoundary( + key: key, + child: Container( + color: CupertinoColors.white, + child: const CupertinoActivityIndicator( + animating: false, + color: Color(0xFF5D3FD3), + radius: 100, + ), + ), + ), + ), + ); + + expect( + find.byType(CupertinoActivityIndicator), + paints + ..rrect(rrect: const RRect.fromLTRBXY(-10, -100 / 3, 10, -100, 10, 10), + color: const Color(0x935d3fd3)), + ); + }); } Widget buildCupertinoActivityIndicator([bool? animating]) { diff --git a/packages/flutter/test/material/progress_indicator_test.dart b/packages/flutter/test/material/progress_indicator_test.dart index 2d81980be7..9ea516d672 100644 --- a/packages/flutter/test/material/progress_indicator_test.dart +++ b/packages/flutter/test/material/progress_indicator_test.dart @@ -822,6 +822,34 @@ void main() { }), ); + testWidgets( + 'Adaptive CircularProgressIndicator can use backgroundColor to change tick color for iOS', + (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: Material( + child: CircularProgressIndicator.adaptive( + backgroundColor: Color(0xFF5D3FD3), + ), + ), + ), + ), + ); + + expect( + find.byType(CupertinoActivityIndicator), + paints + ..rrect(rrect: const RRect.fromLTRBXY(-1, -10 / 3, 1, -10, 1, 1), + color: const Color(0x935D3FD3)), + ); + }, + variant: const TargetPlatformVariant( { + TargetPlatform.iOS, + TargetPlatform.macOS, + }), + ); + testWidgets( 'Adaptive CircularProgressIndicator does not display CupertinoActivityIndicator in non-iOS', (WidgetTester tester) async {