From fad7c36761069b31b664c63e03262d9df9ad2eb3 Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Fri, 12 Mar 2021 16:33:03 -0800 Subject: [PATCH] Removed ProgressIndicator accentColor dependency. (#77976) --- .../lib/src/material/progress_indicator.dart | 26 ++++-- .../material/progress_indicator_test.dart | 84 +++++++++++++++++-- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 144186589e..8e8b456157 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -43,6 +43,7 @@ abstract class ProgressIndicator extends StatefulWidget { Key? key, this.value, this.backgroundColor, + this.color, this.valueColor, this.semanticsLabel, this.semanticsValue, @@ -62,18 +63,25 @@ abstract class ProgressIndicator extends StatefulWidget { /// The progress indicator's background color. /// - /// The current theme's [ThemeData.backgroundColor] by default. + /// The current theme's [ColorScheme.background] by default. /// /// This property is ignored if used in an adaptive constructor inside an iOS /// environment. final Color? backgroundColor; + /// The progress indicator's color. + /// + /// This is only used if [valueColor] is null. If [color] is also null, + /// then it defaults to the current theme's [ColorScheme.primary] by default. + /// + /// This property is ignored if used in an adaptive constructor inside an iOS + /// environment. + final Color? color; + /// The progress indicator's color as an animated value. /// - /// To specify a constant color use: `AlwaysStoppedAnimation(color)`. - /// - /// If null, the progress indicator is rendered with the current theme's - /// [ThemeData.accentColor]. + /// If null, the progress indicator is rendered with [color], or if that is + /// also null then with the current theme's [ColorScheme.primary]. /// /// This property is ignored if used in an adaptive constructor inside an iOS /// environment. @@ -108,8 +116,8 @@ abstract class ProgressIndicator extends StatefulWidget { /// {@endtemplate} final String? semanticsValue; - Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor; - Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor; + Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).colorScheme.background; + Color _getValueColor(BuildContext context) => valueColor?.value ?? color ?? Theme.of(context).colorScheme.primary; @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { @@ -305,6 +313,7 @@ class LinearProgressIndicator extends ProgressIndicator { Key? key, double? value, Color? backgroundColor, + Color? color, Animation? valueColor, this.minHeight, String? semanticsLabel, @@ -314,6 +323,7 @@ class LinearProgressIndicator extends ProgressIndicator { key: key, value: value, backgroundColor: backgroundColor, + color: color, valueColor: valueColor, semanticsLabel: semanticsLabel, semanticsValue: semanticsValue, @@ -544,6 +554,7 @@ class CircularProgressIndicator extends ProgressIndicator { Key? key, double? value, Color? backgroundColor, + Color? color, Animation? valueColor, this.strokeWidth = 4.0, String? semanticsLabel, @@ -553,6 +564,7 @@ class CircularProgressIndicator extends ProgressIndicator { key: key, value: value, backgroundColor: backgroundColor, + color: color, valueColor: valueColor, semanticsLabel: semanticsLabel, semanticsValue: semanticsValue, diff --git a/packages/flutter/test/material/progress_indicator_test.dart b/packages/flutter/test/material/progress_indicator_test.dart index 9a667dec34..9dca7dfeea 100644 --- a/packages/flutter/test/material/progress_indicator_test.dart +++ b/packages/flutter/test/material/progress_indicator_test.dart @@ -172,6 +172,7 @@ void main() { }); testWidgets('LinearProgressIndicator with colors', (WidgetTester tester) async { + // With valueColor & color provided await tester.pumpWidget( const Directionality( textDirection: TextDirection.ltr, @@ -180,20 +181,76 @@ void main() { width: 200.0, child: LinearProgressIndicator( value: 0.25, - valueColor: AlwaysStoppedAnimation(Colors.white), backgroundColor: Colors.black, + color: Colors.blue, + valueColor: AlwaysStoppedAnimation(Colors.white), ), ), ), ), ); + // Should use valueColor expect( find.byType(LinearProgressIndicator), paints ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0)) ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 4.0), color: Colors.white), ); + + // With just color provided + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + width: 200.0, + child: LinearProgressIndicator( + value: 0.25, + backgroundColor: Colors.black, + color: Colors.white12, + ), + ), + ), + ), + ); + + // Should use color + expect( + find.byType(LinearProgressIndicator), + paints + ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0)) + ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 4.0), color: Colors.white12), + ); + + // With no color provided + const Color primaryColor = Color(0xff008800); + final ThemeData theme = ThemeData(colorScheme: ColorScheme.fromSwatch().copyWith(primary: primaryColor)); + await tester.pumpWidget( + Theme( + data: theme, + child: const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + width: 200.0, + child: LinearProgressIndicator( + value: 0.25, + backgroundColor: Colors.black, + ), + ), + ), + ), + ), + ); + + // Should use the theme's primary color + expect( + find.byType(LinearProgressIndicator), + paints + ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0)) + ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 4.0), color: primaryColor), + ); }); testWidgets('LinearProgressIndicator with animation with null colors', (WidgetTester tester) async { @@ -275,22 +332,39 @@ void main() { expect(find.byType(CircularProgressIndicator), paints..arc(strokeWidth: 16.0)); }); - testWidgets('CircularProgressIndicator paint background color', (WidgetTester tester) async { + testWidgets('CircularProgressIndicator paint colors', (WidgetTester tester) async { const Color green = Color(0xFF00FF00); const Color blue = Color(0xFF0000FF); + const Color red = Color(0xFFFF0000); + // With valueColor & color provided await tester.pumpWidget(const CircularProgressIndicator( + color: red, valueColor: AlwaysStoppedAnimation(blue), )); - expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(CircularProgressIndicator), paints..arc(color: blue)); + // With just color provided + await tester.pumpWidget(const CircularProgressIndicator( + color: red, + )); + expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); + expect(find.byType(CircularProgressIndicator), paints..arc(color: red)); + + // With no color provided + await tester.pumpWidget(Theme( + data: ThemeData(colorScheme: ColorScheme.fromSwatch().copyWith(primary: green)), + child: const CircularProgressIndicator(), + )); + expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); + expect(find.byType(CircularProgressIndicator), paints..arc(color: green)); + + // With background await tester.pumpWidget(const CircularProgressIndicator( backgroundColor: green, - valueColor: AlwaysStoppedAnimation(blue), + color: blue, )); - expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 2)); expect(find.byType(CircularProgressIndicator), paints..arc(color: green)..arc(color: blue)); });