Removed ProgressIndicator accentColor dependency. (#77976)
This commit is contained in:
parent
f5cb666f81
commit
fad7c36761
@ -43,6 +43,7 @@ abstract class ProgressIndicator extends StatefulWidget {
|
|||||||
Key? key,
|
Key? key,
|
||||||
this.value,
|
this.value,
|
||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
|
this.color,
|
||||||
this.valueColor,
|
this.valueColor,
|
||||||
this.semanticsLabel,
|
this.semanticsLabel,
|
||||||
this.semanticsValue,
|
this.semanticsValue,
|
||||||
@ -62,18 +63,25 @@ abstract class ProgressIndicator extends StatefulWidget {
|
|||||||
|
|
||||||
/// The progress indicator's background color.
|
/// 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
|
/// This property is ignored if used in an adaptive constructor inside an iOS
|
||||||
/// environment.
|
/// environment.
|
||||||
final Color? backgroundColor;
|
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.
|
/// The progress indicator's color as an animated value.
|
||||||
///
|
///
|
||||||
/// To specify a constant color use: `AlwaysStoppedAnimation<Color>(color)`.
|
/// If null, the progress indicator is rendered with [color], or if that is
|
||||||
///
|
/// also null then with the current theme's [ColorScheme.primary].
|
||||||
/// If null, the progress indicator is rendered with the current theme's
|
|
||||||
/// [ThemeData.accentColor].
|
|
||||||
///
|
///
|
||||||
/// This property is ignored if used in an adaptive constructor inside an iOS
|
/// This property is ignored if used in an adaptive constructor inside an iOS
|
||||||
/// environment.
|
/// environment.
|
||||||
@ -108,8 +116,8 @@ abstract class ProgressIndicator extends StatefulWidget {
|
|||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
final String? semanticsValue;
|
final String? semanticsValue;
|
||||||
|
|
||||||
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
|
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).colorScheme.background;
|
||||||
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor;
|
Color _getValueColor(BuildContext context) => valueColor?.value ?? color ?? Theme.of(context).colorScheme.primary;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||||
@ -305,6 +313,7 @@ class LinearProgressIndicator extends ProgressIndicator {
|
|||||||
Key? key,
|
Key? key,
|
||||||
double? value,
|
double? value,
|
||||||
Color? backgroundColor,
|
Color? backgroundColor,
|
||||||
|
Color? color,
|
||||||
Animation<Color?>? valueColor,
|
Animation<Color?>? valueColor,
|
||||||
this.minHeight,
|
this.minHeight,
|
||||||
String? semanticsLabel,
|
String? semanticsLabel,
|
||||||
@ -314,6 +323,7 @@ class LinearProgressIndicator extends ProgressIndicator {
|
|||||||
key: key,
|
key: key,
|
||||||
value: value,
|
value: value,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
|
color: color,
|
||||||
valueColor: valueColor,
|
valueColor: valueColor,
|
||||||
semanticsLabel: semanticsLabel,
|
semanticsLabel: semanticsLabel,
|
||||||
semanticsValue: semanticsValue,
|
semanticsValue: semanticsValue,
|
||||||
@ -544,6 +554,7 @@ class CircularProgressIndicator extends ProgressIndicator {
|
|||||||
Key? key,
|
Key? key,
|
||||||
double? value,
|
double? value,
|
||||||
Color? backgroundColor,
|
Color? backgroundColor,
|
||||||
|
Color? color,
|
||||||
Animation<Color?>? valueColor,
|
Animation<Color?>? valueColor,
|
||||||
this.strokeWidth = 4.0,
|
this.strokeWidth = 4.0,
|
||||||
String? semanticsLabel,
|
String? semanticsLabel,
|
||||||
@ -553,6 +564,7 @@ class CircularProgressIndicator extends ProgressIndicator {
|
|||||||
key: key,
|
key: key,
|
||||||
value: value,
|
value: value,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
|
color: color,
|
||||||
valueColor: valueColor,
|
valueColor: valueColor,
|
||||||
semanticsLabel: semanticsLabel,
|
semanticsLabel: semanticsLabel,
|
||||||
semanticsValue: semanticsValue,
|
semanticsValue: semanticsValue,
|
||||||
|
@ -172,6 +172,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('LinearProgressIndicator with colors', (WidgetTester tester) async {
|
testWidgets('LinearProgressIndicator with colors', (WidgetTester tester) async {
|
||||||
|
// With valueColor & color provided
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
const Directionality(
|
const Directionality(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
@ -180,20 +181,76 @@ void main() {
|
|||||||
width: 200.0,
|
width: 200.0,
|
||||||
child: LinearProgressIndicator(
|
child: LinearProgressIndicator(
|
||||||
value: 0.25,
|
value: 0.25,
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
|
color: Colors.blue,
|
||||||
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Should use valueColor
|
||||||
expect(
|
expect(
|
||||||
find.byType(LinearProgressIndicator),
|
find.byType(LinearProgressIndicator),
|
||||||
paints
|
paints
|
||||||
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0))
|
..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),
|
..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 {
|
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));
|
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 green = Color(0xFF00FF00);
|
||||||
const Color blue = Color(0xFF0000FF);
|
const Color blue = Color(0xFF0000FF);
|
||||||
|
const Color red = Color(0xFFFF0000);
|
||||||
|
|
||||||
|
// With valueColor & color provided
|
||||||
await tester.pumpWidget(const CircularProgressIndicator(
|
await tester.pumpWidget(const CircularProgressIndicator(
|
||||||
|
color: red,
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(blue),
|
valueColor: AlwaysStoppedAnimation<Color>(blue),
|
||||||
));
|
));
|
||||||
|
|
||||||
expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
|
expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
|
||||||
expect(find.byType(CircularProgressIndicator), paints..arc(color: blue));
|
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(
|
await tester.pumpWidget(const CircularProgressIndicator(
|
||||||
backgroundColor: green,
|
backgroundColor: green,
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(blue),
|
color: blue,
|
||||||
));
|
));
|
||||||
|
|
||||||
expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 2));
|
expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 2));
|
||||||
expect(find.byType(CircularProgressIndicator), paints..arc(color: green)..arc(color: blue));
|
expect(find.byType(CircularProgressIndicator), paints..arc(color: green)..arc(color: blue));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user