Unverified Commit e1671628 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Updated `ProgressIndicator` to M3 (#112139)

parent 71c21d60
...@@ -31,6 +31,7 @@ import 'package:gen_defaults/input_chip_template.dart'; ...@@ -31,6 +31,7 @@ import 'package:gen_defaults/input_chip_template.dart';
import 'package:gen_defaults/input_decorator_template.dart'; import 'package:gen_defaults/input_decorator_template.dart';
import 'package:gen_defaults/navigation_bar_template.dart'; import 'package:gen_defaults/navigation_bar_template.dart';
import 'package:gen_defaults/navigation_rail_template.dart'; import 'package:gen_defaults/navigation_rail_template.dart';
import 'package:gen_defaults/progress_indicator_template.dart';
import 'package:gen_defaults/radio_template.dart'; import 'package:gen_defaults/radio_template.dart';
import 'package:gen_defaults/surface_tint.dart'; import 'package:gen_defaults/surface_tint.dart';
import 'package:gen_defaults/switch_template.dart'; import 'package:gen_defaults/switch_template.dart';
...@@ -80,6 +81,8 @@ Future<void> main(List<String> args) async { ...@@ -80,6 +81,8 @@ Future<void> main(List<String> args) async {
'navigation_drawer.json', 'navigation_drawer.json',
'navigation_rail.json', 'navigation_rail.json',
'palette.json', 'palette.json',
'progress_indicator_circular.json',
'progress_indicator_linear.json',
'radio_button.json', 'radio_button.json',
'segmented_button_outlined.json', 'segmented_button_outlined.json',
'shape.json', 'shape.json',
...@@ -126,6 +129,7 @@ Future<void> main(List<String> args) async { ...@@ -126,6 +129,7 @@ Future<void> main(List<String> args) async {
InputDecoratorTemplate('InputDecorator', '$materialLib/input_decorator.dart', tokens).updateFile(); InputDecoratorTemplate('InputDecorator', '$materialLib/input_decorator.dart', tokens).updateFile();
NavigationBarTemplate('NavigationBar', '$materialLib/navigation_bar.dart', tokens).updateFile(); NavigationBarTemplate('NavigationBar', '$materialLib/navigation_bar.dart', tokens).updateFile();
NavigationRailTemplate('NavigationRail', '$materialLib/navigation_rail.dart', tokens).updateFile(); NavigationRailTemplate('NavigationRail', '$materialLib/navigation_rail.dart', tokens).updateFile();
ProgressIndicatorTemplate('ProgressIndicator', '$materialLib/progress_indicator.dart', tokens).updateFile();
RadioTemplate('Radio<T>', '$materialLib/radio.dart', tokens).updateFile(); RadioTemplate('Radio<T>', '$materialLib/radio.dart', tokens).updateFile();
SurfaceTintTemplate('SurfaceTint', '$materialLib/elevation_overlay.dart', tokens).updateFile(); SurfaceTintTemplate('SurfaceTint', '$materialLib/elevation_overlay.dart', tokens).updateFile();
SwitchTemplate('Switch', '$materialLib/switch.dart', tokens).updateFile(); SwitchTemplate('Switch', '$materialLib/switch.dart', tokens).updateFile();
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'template.dart';
class ProgressIndicatorTemplate extends TokenTemplate {
const ProgressIndicatorTemplate(super.blockName, super.fileName, super.tokens, {
super.colorSchemePrefix = '_colors.',
});
@override
String generate() => '''
class _Circular${blockName}DefaultsM3 extends ProgressIndicatorThemeData {
_Circular${blockName}DefaultsM3(this.context);
final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
static const double circularProgressIndicatorSize = ${tokens['md.comp.circular-progress-indicator.size']};
@override
Color get color => ${componentColor('md.comp.circular-progress-indicator.active-indicator')};
}
class _Linear${blockName}DefaultsM3 extends ProgressIndicatorThemeData {
_Linear${blockName}DefaultsM3(this.context);
final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
@override
Color get color => ${componentColor('md.comp.linear-progress-indicator.active-indicator')};
@override
Color get linearTrackColor => ${componentColor('md.comp.linear-progress-indicator.track')};
@override
double get linearMinHeight => ${tokens['md.comp.linear-progress-indicator.track.height']};
}
''';
}
...@@ -108,11 +108,11 @@ abstract class ProgressIndicator extends StatefulWidget { ...@@ -108,11 +108,11 @@ abstract class ProgressIndicator extends StatefulWidget {
/// {@endtemplate} /// {@endtemplate}
final String? semanticsValue; final String? semanticsValue;
Color _getValueColor(BuildContext context) { Color _getValueColor(BuildContext context, {Color? defaultColor}) {
return return valueColor?.value ??
valueColor?.value ??
color ?? color ??
ProgressIndicatorTheme.of(context).color ?? ProgressIndicatorTheme.of(context).color ??
defaultColor ??
Theme.of(context).colorScheme.primary; Theme.of(context).colorScheme.primary;
} }
...@@ -331,12 +331,17 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with ...@@ -331,12 +331,17 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with
} }
Widget _buildIndicator(BuildContext context, double animationValue, TextDirection textDirection) { Widget _buildIndicator(BuildContext context, double animationValue, TextDirection textDirection) {
final ProgressIndicatorThemeData defaults = Theme.of(context).useMaterial3
? _LinearProgressIndicatorDefaultsM3(context)
: _LinearProgressIndicatorDefaultsM2(context);
final ProgressIndicatorThemeData indicatorTheme = ProgressIndicatorTheme.of(context); final ProgressIndicatorThemeData indicatorTheme = ProgressIndicatorTheme.of(context);
final Color trackColor = final Color trackColor = widget.backgroundColor ??
widget.backgroundColor ??
indicatorTheme.linearTrackColor ?? indicatorTheme.linearTrackColor ??
Theme.of(context).colorScheme.background; defaults.linearTrackColor!;
final double minHeight = widget.minHeight ?? indicatorTheme.linearMinHeight ?? 4.0; final double minHeight = widget.minHeight ??
indicatorTheme.linearMinHeight ??
defaults.linearMinHeight!;
return widget._buildSemanticsWrapper( return widget._buildSemanticsWrapper(
context: context, context: context,
...@@ -348,7 +353,7 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with ...@@ -348,7 +353,7 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with
child: CustomPaint( child: CustomPaint(
painter: _LinearProgressIndicatorPainter( painter: _LinearProgressIndicatorPainter(
backgroundColor: trackColor, backgroundColor: trackColor,
valueColor: widget._getValueColor(context), valueColor: widget._getValueColor(context, defaultColor: defaults.color),
value: widget.value, // may be null value: widget.value, // may be null
animationValue: animationValue, // ignored if widget.value is not null animationValue: animationValue, // ignored if widget.value is not null
textDirection: textDirection, textDirection: textDirection,
...@@ -580,29 +585,44 @@ class _CircularProgressIndicatorState extends State<CircularProgressIndicator> w ...@@ -580,29 +585,44 @@ class _CircularProgressIndicatorState extends State<CircularProgressIndicator> w
} }
Widget _buildMaterialIndicator(BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) { Widget _buildMaterialIndicator(BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) {
final ProgressIndicatorThemeData defaults = Theme.of(context).useMaterial3
? _CircularProgressIndicatorDefaultsM3(context)
: _CircularProgressIndicatorDefaultsM2(context);
final Color? trackColor = widget.backgroundColor ?? ProgressIndicatorTheme.of(context).circularTrackColor; final Color? trackColor = widget.backgroundColor ?? ProgressIndicatorTheme.of(context).circularTrackColor;
return widget._buildSemanticsWrapper( Widget progressIndicator = Container(
context: context, constraints: const BoxConstraints(
child: Container( minWidth: _kMinCircularProgressIndicatorSize,
constraints: const BoxConstraints( minHeight: _kMinCircularProgressIndicatorSize,
minWidth: _kMinCircularProgressIndicatorSize, ),
minHeight: _kMinCircularProgressIndicatorSize, child: CustomPaint(
), painter: _CircularProgressIndicatorPainter(
child: CustomPaint( backgroundColor: trackColor,
painter: _CircularProgressIndicatorPainter( valueColor: widget._getValueColor(context, defaultColor: defaults.color),
backgroundColor: trackColor, value: widget.value, // may be null
valueColor: widget._getValueColor(context), headValue: headValue, // remaining arguments are ignored if widget.value is not null
value: widget.value, // may be null tailValue: tailValue,
headValue: headValue, // remaining arguments are ignored if widget.value is not null offsetValue: offsetValue,
tailValue: tailValue, rotationValue: rotationValue,
offsetValue: offsetValue, strokeWidth: widget.strokeWidth,
rotationValue: rotationValue,
strokeWidth: widget.strokeWidth,
),
), ),
), ),
); );
if (Theme.of(context).useMaterial3) {
progressIndicator = SizedBox(
height: _CircularProgressIndicatorDefaultsM3.circularProgressIndicatorSize,
width: _CircularProgressIndicatorDefaultsM3.circularProgressIndicatorSize,
child: Center(
child: progressIndicator
),
);
}
return widget._buildSemanticsWrapper(
context: context,
child: progressIndicator,
);
} }
Widget _buildAnimation() { Widget _buildAnimation() {
...@@ -866,3 +886,69 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState { ...@@ -866,3 +886,69 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
); );
} }
} }
// Hand coded defaults based on Material Design 2.
class _CircularProgressIndicatorDefaultsM2 extends ProgressIndicatorThemeData {
_CircularProgressIndicatorDefaultsM2(this.context);
final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
@override
Color get color => _colors.primary;
}
class _LinearProgressIndicatorDefaultsM2 extends ProgressIndicatorThemeData {
_LinearProgressIndicatorDefaultsM2(this.context);
final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
@override
Color get color => _colors.primary;
@override
Color get linearTrackColor => _colors.background;
@override
double get linearMinHeight => 4.0;
}
// BEGIN GENERATED TOKEN PROPERTIES - ProgressIndicator
// Do not edit by hand. The code between the "BEGIN GENERATED" and
// "END GENERATED" comments are generated from data in the Material
// Design token database by the script:
// dev/tools/gen_defaults/bin/gen_defaults.dart.
// Token database version: v0_132
class _CircularProgressIndicatorDefaultsM3 extends ProgressIndicatorThemeData {
_CircularProgressIndicatorDefaultsM3(this.context);
final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
static const double circularProgressIndicatorSize = 48.0;
@override
Color get color => _colors.primary;
}
class _LinearProgressIndicatorDefaultsM3 extends ProgressIndicatorThemeData {
_LinearProgressIndicatorDefaultsM3(this.context);
final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
@override
Color get color => _colors.primary;
@override
Color get linearTrackColor => _colors.surfaceVariant;
@override
double get linearMinHeight => 4.0;
}
// END GENERATED TOKEN PROPERTIES - ProgressIndicator
...@@ -1266,6 +1266,7 @@ class ThemeData with Diagnosticable { ...@@ -1266,6 +1266,7 @@ class ThemeData with Diagnosticable {
/// * Lists: [ListTile] /// * Lists: [ListTile]
/// * Navigation bar: [NavigationBar] (new, replacing [BottomNavigationBar]) /// * Navigation bar: [NavigationBar] (new, replacing [BottomNavigationBar])
/// * [Navigation rail](https://m3.material.io/components/navigation-rail): [NavigationRail] /// * [Navigation rail](https://m3.material.io/components/navigation-rail): [NavigationRail]
/// * Progress indicators: [CircularProgressIndicator], [LinearProgressIndicator]
/// * Radio button: [Radio] /// * Radio button: [Radio]
/// * Switch: [Switch] /// * Switch: [Switch]
/// * Top app bar: [AppBar] /// * Top app bar: [AppBar]
......
...@@ -20,6 +20,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -20,6 +20,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
void main() { void main() {
final ThemeData theme = ThemeData();
// The "can be constructed" tests that follow are primarily to ensure that any // The "can be constructed" tests that follow are primarily to ensure that any
// animations started by the progress indicators are stopped at dispose() time. // animations started by the progress indicators are stopped at dispose() time.
...@@ -27,12 +28,15 @@ void main() { ...@@ -27,12 +28,15 @@ void main() {
testWidgets('LinearProgressIndicator(value: 0.0) can be constructed and has empty semantics by default', (WidgetTester tester) async { testWidgets('LinearProgressIndicator(value: 0.0) can be constructed and has empty semantics by default', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator(value: 0.0), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(value: 0.0),
),
), ),
), ),
), ),
...@@ -45,12 +49,15 @@ void main() { ...@@ -45,12 +49,15 @@ void main() {
testWidgets('LinearProgressIndicator(value: null) can be constructed and has empty semantics by default', (WidgetTester tester) async { testWidgets('LinearProgressIndicator(value: null) can be constructed and has empty semantics by default', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.rtl, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.rtl,
width: 200.0, child: Center(
child: LinearProgressIndicator(), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(),
),
), ),
), ),
), ),
...@@ -62,12 +69,15 @@ void main() { ...@@ -62,12 +69,15 @@ void main() {
testWidgets('LinearProgressIndicator custom minHeight', (WidgetTester tester) async { testWidgets('LinearProgressIndicator custom minHeight', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator(value: 0.25, minHeight: 2.0), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(value: 0.25, minHeight: 2.0),
),
), ),
), ),
), ),
...@@ -82,7 +92,7 @@ void main() { ...@@ -82,7 +92,7 @@ void main() {
// Same test, but using the theme // Same test, but using the theme
await tester.pumpWidget( await tester.pumpWidget(
Theme( Theme(
data: ThemeData( data: theme.copyWith(
progressIndicatorTheme: const ProgressIndicatorThemeData( progressIndicatorTheme: const ProgressIndicatorThemeData(
linearMinHeight: 2.0, linearMinHeight: 2.0,
), ),
...@@ -108,12 +118,15 @@ void main() { ...@@ -108,12 +118,15 @@ void main() {
testWidgets('LinearProgressIndicator paint (LTR)', (WidgetTester tester) async { testWidgets('LinearProgressIndicator paint (LTR)', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator(value: 0.25), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(value: 0.25),
),
), ),
), ),
), ),
...@@ -131,12 +144,15 @@ void main() { ...@@ -131,12 +144,15 @@ void main() {
testWidgets('LinearProgressIndicator paint (RTL)', (WidgetTester tester) async { testWidgets('LinearProgressIndicator paint (RTL)', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.rtl, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.rtl,
width: 200.0, child: Center(
child: LinearProgressIndicator(value: 0.25), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(value: 0.25),
),
), ),
), ),
), ),
...@@ -154,12 +170,15 @@ void main() { ...@@ -154,12 +170,15 @@ void main() {
testWidgets('LinearProgressIndicator indeterminate (LTR)', (WidgetTester tester) async { testWidgets('LinearProgressIndicator indeterminate (LTR)', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator(), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(),
),
), ),
), ),
), ),
...@@ -181,12 +200,15 @@ void main() { ...@@ -181,12 +200,15 @@ void main() {
testWidgets('LinearProgressIndicator paint (RTL)', (WidgetTester tester) async { testWidgets('LinearProgressIndicator paint (RTL)', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.rtl, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.rtl,
width: 200.0, child: Center(
child: LinearProgressIndicator(), child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(),
),
), ),
), ),
), ),
...@@ -209,16 +231,19 @@ void main() { ...@@ -209,16 +231,19 @@ void main() {
testWidgets('LinearProgressIndicator with colors', (WidgetTester tester) async { testWidgets('LinearProgressIndicator with colors', (WidgetTester tester) async {
// With valueColor & color provided // With valueColor & color provided
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator( child: SizedBox(
value: 0.25, width: 200.0,
backgroundColor: Colors.black, child: LinearProgressIndicator(
color: Colors.blue, value: 0.25,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white), backgroundColor: Colors.black,
color: Colors.blue,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
), ),
), ),
), ),
...@@ -235,15 +260,18 @@ void main() { ...@@ -235,15 +260,18 @@ void main() {
// With just color provided // With just color provided
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator( child: SizedBox(
value: 0.25, width: 200.0,
backgroundColor: Colors.black, child: LinearProgressIndicator(
color: Colors.white12, value: 0.25,
backgroundColor: Colors.black,
color: Colors.white12,
),
), ),
), ),
), ),
...@@ -260,10 +288,9 @@ void main() { ...@@ -260,10 +288,9 @@ void main() {
// With no color provided // With no color provided
const Color primaryColor = Color(0xff008800); const Color primaryColor = Color(0xff008800);
final ThemeData theme = ThemeData(colorScheme: ColorScheme.fromSwatch().copyWith(primary: primaryColor));
await tester.pumpWidget( await tester.pumpWidget(
Theme( Theme(
data: theme, data: theme.copyWith(colorScheme: ColorScheme.fromSwatch().copyWith(primary: primaryColor)),
child: const Directionality( child: const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(
...@@ -291,7 +318,7 @@ void main() { ...@@ -291,7 +318,7 @@ void main() {
const Color indicatorColor = Color(0xff0000ff); const Color indicatorColor = Color(0xff0000ff);
await tester.pumpWidget( await tester.pumpWidget(
Theme( Theme(
data: ThemeData( data: theme.copyWith(
progressIndicatorTheme: const ProgressIndicatorThemeData( progressIndicatorTheme: const ProgressIndicatorThemeData(
color: indicatorColor, color: indicatorColor,
linearTrackColor: Colors.black, linearTrackColor: Colors.black,
...@@ -323,15 +350,18 @@ void main() { ...@@ -323,15 +350,18 @@ void main() {
testWidgets('LinearProgressIndicator with animation with null colors', (WidgetTester tester) async { testWidgets('LinearProgressIndicator with animation with null colors', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: LinearProgressIndicator( child: SizedBox(
value: 0.25, width: 200.0,
valueColor: AlwaysStoppedAnimation<Color?>(null), child: LinearProgressIndicator(
backgroundColor: Colors.black, value: 0.25,
valueColor: AlwaysStoppedAnimation<Color?>(null),
backgroundColor: Colors.black,
),
), ),
), ),
), ),
...@@ -349,10 +379,13 @@ void main() { ...@@ -349,10 +379,13 @@ void main() {
testWidgets('CircularProgressIndicator(value: 0.0) can be constructed and has value semantics by default', (WidgetTester tester) async { testWidgets('CircularProgressIndicator(value: 0.0) can be constructed and has value semantics by default', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: CircularProgressIndicator(value: 0.0), textDirection: TextDirection.ltr,
child: Center(
child: CircularProgressIndicator(value: 0.0),
),
), ),
), ),
); );
...@@ -367,8 +400,11 @@ void main() { ...@@ -367,8 +400,11 @@ void main() {
testWidgets('CircularProgressIndicator(value: null) can be constructed and has empty semantics by default', (WidgetTester tester) async { testWidgets('CircularProgressIndicator(value: null) can be constructed and has empty semantics by default', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget( await tester.pumpWidget(
const Center( Theme(
child: CircularProgressIndicator(), data: theme,
child: const Center(
child: CircularProgressIndicator(),
),
), ),
); );
...@@ -377,25 +413,31 @@ void main() { ...@@ -377,25 +413,31 @@ void main() {
}); });
testWidgets('LinearProgressIndicator causes a repaint when it changes', (WidgetTester tester) async { testWidgets('LinearProgressIndicator causes a repaint when it changes', (WidgetTester tester) async {
await tester.pumpWidget(Directionality( await tester.pumpWidget(Theme(
textDirection: TextDirection.ltr, data: theme,
child: ListView(children: const <Widget>[LinearProgressIndicator(value: 0.0)]), child: Directionality(
textDirection: TextDirection.ltr,
child: ListView(children: const <Widget>[LinearProgressIndicator(value: 0.0)]),
),
)); ));
final List<Layer> layers1 = tester.layers; final List<Layer> layers1 = tester.layers;
await tester.pumpWidget(Directionality( await tester.pumpWidget(Theme(
textDirection: TextDirection.ltr, data: theme,
child: ListView(children: const <Widget>[LinearProgressIndicator(value: 0.5)]), child: Directionality(
textDirection: TextDirection.ltr,
child: ListView(children: const <Widget>[LinearProgressIndicator(value: 0.5)]),
),
)); ));
final List<Layer> layers2 = tester.layers; final List<Layer> layers2 = tester.layers;
expect(layers1, isNot(equals(layers2))); expect(layers1, isNot(equals(layers2)));
}); });
testWidgets('CircularProgressIndicator stoke width', (WidgetTester tester) async { testWidgets('CircularProgressIndicator stoke width', (WidgetTester tester) async {
await tester.pumpWidget(const CircularProgressIndicator()); await tester.pumpWidget(Theme(data: theme, child: const CircularProgressIndicator()));
expect(find.byType(CircularProgressIndicator), paints..arc(strokeWidth: 4.0)); expect(find.byType(CircularProgressIndicator), paints..arc(strokeWidth: 4.0));
await tester.pumpWidget(const CircularProgressIndicator(strokeWidth: 16.0)); await tester.pumpWidget(Theme(data: theme, child: const CircularProgressIndicator(strokeWidth: 16.0)));
expect(find.byType(CircularProgressIndicator), paints..arc(strokeWidth: 16.0)); expect(find.byType(CircularProgressIndicator), paints..arc(strokeWidth: 16.0));
}); });
...@@ -406,39 +448,48 @@ void main() { ...@@ -406,39 +448,48 @@ void main() {
const Color red = Color(0xFFFF0000); const Color red = Color(0xFFFF0000);
// With valueColor & color provided // With valueColor & color provided
await tester.pumpWidget(const CircularProgressIndicator( await tester.pumpWidget(Theme(
color: red, data: theme,
valueColor: AlwaysStoppedAnimation<Color>(blue), child: const CircularProgressIndicator(
color: red,
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 // With just color provided
await tester.pumpWidget(const CircularProgressIndicator( await tester.pumpWidget(Theme(
color: red, data: theme,
child: const CircularProgressIndicator(
color: red,
),
)); ));
expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
expect(find.byType(CircularProgressIndicator), paints..arc(color: red)); expect(find.byType(CircularProgressIndicator), paints..arc(color: red));
// With no color provided // With no color provided
await tester.pumpWidget(Theme( await tester.pumpWidget(Theme(
data: ThemeData(colorScheme: ColorScheme.fromSwatch().copyWith(primary: green)), data: theme.copyWith(colorScheme: ColorScheme.fromSwatch().copyWith(primary: green)),
child: const CircularProgressIndicator(), child: const CircularProgressIndicator(),
)); ));
expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(CircularProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
expect(find.byType(CircularProgressIndicator), paints..arc(color: green)); expect(find.byType(CircularProgressIndicator), paints..arc(color: green));
// With background // With background
await tester.pumpWidget(const CircularProgressIndicator( await tester.pumpWidget(Theme(
backgroundColor: green, data: theme,
color: blue, child: const CircularProgressIndicator(
backgroundColor: green,
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));
// With ProgressIndicatorTheme // With ProgressIndicatorTheme
await tester.pumpWidget(Theme( await tester.pumpWidget(Theme(
data: ThemeData(progressIndicatorTheme: const ProgressIndicatorThemeData( data: theme.copyWith(progressIndicatorTheme: const ProgressIndicatorThemeData(
color: green, color: green,
circularTrackColor: blue, circularTrackColor: blue,
)), )),
...@@ -454,32 +505,41 @@ void main() { ...@@ -454,32 +505,41 @@ void main() {
const Color red = Color(0xFFFF0000); const Color red = Color(0xFFFF0000);
// With valueColor & color provided // With valueColor & color provided
await tester.pumpWidget(const RefreshProgressIndicator( await tester.pumpWidget(Theme(
color: red, data: theme,
valueColor: AlwaysStoppedAnimation<Color>(blue), child: const RefreshProgressIndicator(
color: red,
valueColor: AlwaysStoppedAnimation<Color>(blue),
),
)); ));
expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
expect(find.byType(RefreshProgressIndicator), paints..arc(color: blue)); expect(find.byType(RefreshProgressIndicator), paints..arc(color: blue));
// With just color provided // With just color provided
await tester.pumpWidget(const RefreshProgressIndicator( await tester.pumpWidget(Theme(
color: red, data: theme,
child: const RefreshProgressIndicator(
color: red,
),
)); ));
expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
expect(find.byType(RefreshProgressIndicator), paints..arc(color: red)); expect(find.byType(RefreshProgressIndicator), paints..arc(color: red));
// With no color provided // With no color provided
await tester.pumpWidget(Theme( await tester.pumpWidget(Theme(
data: ThemeData(colorScheme: ColorScheme.fromSwatch().copyWith(primary: green)), data: theme.copyWith(colorScheme: ColorScheme.fromSwatch().copyWith(primary: green)),
child: const RefreshProgressIndicator(), child: const RefreshProgressIndicator(),
)); ));
expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
expect(find.byType(RefreshProgressIndicator), paints..arc(color: green)); expect(find.byType(RefreshProgressIndicator), paints..arc(color: green));
// With background // With background
await tester.pumpWidget(const RefreshProgressIndicator( await tester.pumpWidget(Theme(
color: blue, data: theme,
backgroundColor: green, child: const RefreshProgressIndicator(
color: blue,
backgroundColor: green,
),
)); ));
expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1)); expect(find.byType(RefreshProgressIndicator), paintsExactlyCountTimes(#drawArc, 1));
expect(find.byType(RefreshProgressIndicator), paints..arc(color: blue)); expect(find.byType(RefreshProgressIndicator), paints..arc(color: blue));
...@@ -492,7 +552,7 @@ void main() { ...@@ -492,7 +552,7 @@ void main() {
// With ProgressIndicatorTheme // With ProgressIndicatorTheme
await tester.pumpWidget(Theme( await tester.pumpWidget(Theme(
data: ThemeData(progressIndicatorTheme: const ProgressIndicatorThemeData( data: theme.copyWith(progressIndicatorTheme: const ProgressIndicatorThemeData(
color: green, color: green,
refreshBackgroundColor: blue, refreshBackgroundColor: blue,
)), )),
...@@ -512,12 +572,15 @@ void main() { ...@@ -512,12 +572,15 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/13782 // Regression test for https://github.com/flutter/flutter/issues/13782
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 200.0, child: Center(
child: RefreshProgressIndicator(), child: SizedBox(
width: 200.0,
child: RefreshProgressIndicator(),
),
), ),
), ),
), ),
...@@ -551,14 +614,17 @@ void main() { ...@@ -551,14 +614,17 @@ void main() {
double? progressValue; double? progressValue;
late StateSetter setState; late StateSetter setState;
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: Directionality(
child: StatefulBuilder( textDirection: TextDirection.ltr,
builder: (BuildContext context, StateSetter setter) { child: Center(
setState = setter; child: StatefulBuilder(
return CircularProgressIndicator(value: progressValue); builder: (BuildContext context, StateSetter setter) {
}, setState = setter;
return CircularProgressIndicator(value: progressValue);
},
),
), ),
), ),
), ),
...@@ -576,13 +642,16 @@ void main() { ...@@ -576,13 +642,16 @@ void main() {
testWidgets('LinearProgressIndicator with height 12.0', (WidgetTester tester) async { testWidgets('LinearProgressIndicator with height 12.0', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 100.0, child: Center(
height: 12.0, child: SizedBox(
child: LinearProgressIndicator(value: 0.25), width: 100.0,
height: 12.0,
child: LinearProgressIndicator(value: 0.25),
),
), ),
), ),
), ),
...@@ -598,13 +667,16 @@ void main() { ...@@ -598,13 +667,16 @@ void main() {
testWidgets('LinearProgressIndicator with a height less than the minimum', (WidgetTester tester) async { testWidgets('LinearProgressIndicator with a height less than the minimum', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 100.0, child: Center(
height: 3.0, child: SizedBox(
child: LinearProgressIndicator(value: 0.25), width: 100.0,
height: 3.0,
child: LinearProgressIndicator(value: 0.25),
),
), ),
), ),
), ),
...@@ -620,13 +692,16 @@ void main() { ...@@ -620,13 +692,16 @@ void main() {
testWidgets('LinearProgressIndicator with default height', (WidgetTester tester) async { testWidgets('LinearProgressIndicator with default height', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: Center( child: const Directionality(
child: SizedBox( textDirection: TextDirection.ltr,
width: 100.0, child: Center(
height: 4.0, child: SizedBox(
child: LinearProgressIndicator(value: 0.25), width: 100.0,
height: 4.0,
child: LinearProgressIndicator(value: 0.25),
),
), ),
), ),
), ),
...@@ -646,13 +721,16 @@ void main() { ...@@ -646,13 +721,16 @@ void main() {
const String label = 'Label'; const String label = 'Label';
const String value = '25%'; const String value = '25%';
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: LinearProgressIndicator( child: Directionality(
key: key, textDirection: TextDirection.ltr,
value: 0.25, child: LinearProgressIndicator(
semanticsLabel: label, key: key,
semanticsValue: value, value: 0.25,
semanticsLabel: label,
semanticsValue: value,
),
), ),
), ),
); );
...@@ -671,12 +749,15 @@ void main() { ...@@ -671,12 +749,15 @@ void main() {
final GlobalKey key = GlobalKey(); final GlobalKey key = GlobalKey();
const String label = 'Label'; const String label = 'Label';
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: LinearProgressIndicator( child: Directionality(
key: key, textDirection: TextDirection.ltr,
value: 0.25, child: LinearProgressIndicator(
semanticsLabel: label, key: key,
value: 0.25,
semanticsLabel: label,
),
), ),
), ),
); );
...@@ -694,11 +775,14 @@ void main() { ...@@ -694,11 +775,14 @@ void main() {
final SemanticsHandle handle = tester.ensureSemantics(); final SemanticsHandle handle = tester.ensureSemantics();
final GlobalKey key = GlobalKey(); final GlobalKey key = GlobalKey();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: LinearProgressIndicator( child: Directionality(
key: key, textDirection: TextDirection.ltr,
value: 0.25, child: LinearProgressIndicator(
key: key,
value: 0.25,
),
), ),
), ),
); );
...@@ -713,12 +797,15 @@ void main() { ...@@ -713,12 +797,15 @@ void main() {
final GlobalKey key = GlobalKey(); final GlobalKey key = GlobalKey();
const String label = 'Progress'; const String label = 'Progress';
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: LinearProgressIndicator( child: Directionality(
key: key, textDirection: TextDirection.ltr,
value: 0.25, child: LinearProgressIndicator(
semanticsLabel: label, key: key,
value: 0.25,
semanticsLabel: label,
),
), ),
), ),
); );
...@@ -737,13 +824,16 @@ void main() { ...@@ -737,13 +824,16 @@ void main() {
const String label = 'Label'; const String label = 'Label';
const String value = '25%'; const String value = '25%';
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: CircularProgressIndicator( child: Directionality(
key: key, textDirection: TextDirection.ltr,
value: 0.25, child: CircularProgressIndicator(
semanticsLabel: label, key: key,
semanticsValue: value, value: 0.25,
semanticsLabel: label,
semanticsValue: value,
),
), ),
), ),
); );
...@@ -763,12 +853,15 @@ void main() { ...@@ -763,12 +853,15 @@ void main() {
const String label = 'Label'; const String label = 'Label';
const String value = '25%'; const String value = '25%';
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Theme(
textDirection: TextDirection.ltr, data: theme,
child: RefreshProgressIndicator( child: Directionality(
key: key, textDirection: TextDirection.ltr,
semanticsLabel: label, child: RefreshProgressIndicator(
semanticsValue: value, key: key,
semanticsLabel: label,
semanticsValue: value,
),
), ),
), ),
); );
...@@ -805,8 +898,9 @@ void main() { ...@@ -805,8 +898,9 @@ void main() {
'Adaptive CircularProgressIndicator displays CupertinoActivityIndicator in iOS', 'Adaptive CircularProgressIndicator displays CupertinoActivityIndicator in iOS',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( MaterialApp(
home: Scaffold( theme: ThemeData(),
home: const Scaffold(
body: Material( body: Material(
child: CircularProgressIndicator.adaptive(), child: CircularProgressIndicator.adaptive(),
), ),
...@@ -826,8 +920,9 @@ void main() { ...@@ -826,8 +920,9 @@ void main() {
'Adaptive CircularProgressIndicator can use backgroundColor to change tick color for iOS', 'Adaptive CircularProgressIndicator can use backgroundColor to change tick color for iOS',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( MaterialApp(
home: Scaffold( theme: ThemeData(),
home: const Scaffold(
body: Material( body: Material(
child: CircularProgressIndicator.adaptive( child: CircularProgressIndicator.adaptive(
backgroundColor: Color(0xFF5D3FD3), backgroundColor: Color(0xFF5D3FD3),
...@@ -854,8 +949,9 @@ void main() { ...@@ -854,8 +949,9 @@ void main() {
'Adaptive CircularProgressIndicator does not display CupertinoActivityIndicator in non-iOS', 'Adaptive CircularProgressIndicator does not display CupertinoActivityIndicator in non-iOS',
(WidgetTester tester) async { (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( MaterialApp(
home: Scaffold( theme: theme,
home: const Scaffold(
body: Material( body: Material(
child: CircularProgressIndicator.adaptive(), child: CircularProgressIndicator.adaptive(),
), ),
...@@ -893,7 +989,7 @@ void main() { ...@@ -893,7 +989,7 @@ void main() {
); );
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
home: progressTheme, home: Theme(data: theme, child: progressTheme),
)); ));
final Widget wrappedTheme = progressTheme.wrap(builderContext, Container()); final Widget wrappedTheme = progressTheme.wrap(builderContext, Container());
...@@ -903,6 +999,21 @@ void main() { ...@@ -903,6 +999,21 @@ void main() {
expect(wrappedTheme, isInstanceOf<ProgressIndicatorTheme>()); expect(wrappedTheme, isInstanceOf<ProgressIndicatorTheme>());
expect((wrappedTheme as ProgressIndicatorTheme).data, themeData); expect((wrappedTheme as ProgressIndicatorTheme).data, themeData);
}); });
testWidgets('default size of CircularProgressIndicator is 48x48 - M3', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: theme.copyWith(useMaterial3: true),
home: const Scaffold(
body: Material(
child: CircularProgressIndicator(),
),
),
),
);
expect(tester.getSize(find.byType(CircularProgressIndicator)), const Size(48, 48));
});
} }
class _RefreshProgressIndicatorGolden extends StatefulWidget { class _RefreshProgressIndicatorGolden extends StatefulWidget {
......
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