Unverified Commit acb61ace authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

[CupertinoActivityIndicator] Add `color` parameter (#92172)

parent d196fe0f
......@@ -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<CupertinoActivityIndicator>
child: CustomPaint(
painter: _CupertinoActivityIndicatorPainter(
position: _controller,
activeColor:
CupertinoDynamicColor.resolve(_kActiveTickColor, context),
activeColor: widget.color ?? CupertinoDynamicColor.resolve(_kActiveTickColor, context),
radius: widget.radius,
progress: widget.progress,
),
......
......@@ -594,7 +594,8 @@ class _CircularProgressIndicatorState extends State<CircularProgressIndicator> 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) {
......
......@@ -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]) {
......
......@@ -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> {
TargetPlatform.iOS,
TargetPlatform.macOS,
}),
);
testWidgets(
'Adaptive CircularProgressIndicator does not display CupertinoActivityIndicator in non-iOS',
(WidgetTester tester) async {
......
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