@@ -108,11 +108,11 @@ abstract class ProgressIndicator extends StatefulWidget {
108108 /// {@endtemplate}
109109 final String ? semanticsValue;
110110
111- Color _getValueColor (BuildContext context) {
112- return
113- valueColor? .value ??
111+ Color _getValueColor (BuildContext context, {Color ? defaultColor}) {
112+ return valueColor? .value ??
114113 color ??
115114 ProgressIndicatorTheme .of (context).color ??
115+ defaultColor ??
116116 Theme .of (context).colorScheme.primary;
117117 }
118118
@@ -331,12 +331,17 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with
331331 }
332332
333333 Widget _buildIndicator (BuildContext context, double animationValue, TextDirection textDirection) {
334+ final ProgressIndicatorThemeData defaults = Theme .of (context).useMaterial3
335+ ? _LinearProgressIndicatorDefaultsM3 (context)
336+ : _LinearProgressIndicatorDefaultsM2 (context);
337+
334338 final ProgressIndicatorThemeData indicatorTheme = ProgressIndicatorTheme .of (context);
335- final Color trackColor =
336- widget.backgroundColor ??
339+ final Color trackColor = widget.backgroundColor ??
337340 indicatorTheme.linearTrackColor ??
338- Theme .of (context).colorScheme.background;
339- final double minHeight = widget.minHeight ?? indicatorTheme.linearMinHeight ?? 4.0 ;
341+ defaults.linearTrackColor! ;
342+ final double minHeight = widget.minHeight ??
343+ indicatorTheme.linearMinHeight ??
344+ defaults.linearMinHeight! ;
340345
341346 return widget._buildSemanticsWrapper (
342347 context: context,
@@ -348,7 +353,7 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with
348353 child: CustomPaint (
349354 painter: _LinearProgressIndicatorPainter (
350355 backgroundColor: trackColor,
351- valueColor: widget._getValueColor (context),
356+ valueColor: widget._getValueColor (context, defaultColor : defaults.color ),
352357 value: widget.value, // may be null
353358 animationValue: animationValue, // ignored if widget.value is not null
354359 textDirection: textDirection,
@@ -580,29 +585,44 @@ class _CircularProgressIndicatorState extends State<CircularProgressIndicator> w
580585 }
581586
582587 Widget _buildMaterialIndicator (BuildContext context, double headValue, double tailValue, double offsetValue, double rotationValue) {
588+ final ProgressIndicatorThemeData defaults = Theme .of (context).useMaterial3
589+ ? _CircularProgressIndicatorDefaultsM3 (context)
590+ : _CircularProgressIndicatorDefaultsM2 (context);
583591 final Color ? trackColor = widget.backgroundColor ?? ProgressIndicatorTheme .of (context).circularTrackColor;
584592
585- return widget._buildSemanticsWrapper (
586- context: context,
587- child: Container (
588- constraints: const BoxConstraints (
589- minWidth: _kMinCircularProgressIndicatorSize,
590- minHeight: _kMinCircularProgressIndicatorSize,
591- ),
592- child: CustomPaint (
593- painter: _CircularProgressIndicatorPainter (
594- backgroundColor: trackColor,
595- valueColor: widget._getValueColor (context),
596- value: widget.value, // may be null
597- headValue: headValue, // remaining arguments are ignored if widget.value is not null
598- tailValue: tailValue,
599- offsetValue: offsetValue,
600- rotationValue: rotationValue,
601- strokeWidth: widget.strokeWidth,
602- ),
593+ Widget progressIndicator = Container (
594+ constraints: const BoxConstraints (
595+ minWidth: _kMinCircularProgressIndicatorSize,
596+ minHeight: _kMinCircularProgressIndicatorSize,
597+ ),
598+ child: CustomPaint (
599+ painter: _CircularProgressIndicatorPainter (
600+ backgroundColor: trackColor,
601+ valueColor: widget._getValueColor (context, defaultColor: defaults.color),
602+ value: widget.value, // may be null
603+ headValue: headValue, // remaining arguments are ignored if widget.value is not null
604+ tailValue: tailValue,
605+ offsetValue: offsetValue,
606+ rotationValue: rotationValue,
607+ strokeWidth: widget.strokeWidth,
603608 ),
604609 ),
605610 );
611+
612+ if (Theme .of (context).useMaterial3) {
613+ progressIndicator = SizedBox (
614+ height: _CircularProgressIndicatorDefaultsM3 .circularProgressIndicatorSize,
615+ width: _CircularProgressIndicatorDefaultsM3 .circularProgressIndicatorSize,
616+ child: Center (
617+ child: progressIndicator
618+ ),
619+ );
620+ }
621+
622+ return widget._buildSemanticsWrapper (
623+ context: context,
624+ child: progressIndicator,
625+ );
606626 }
607627
608628 Widget _buildAnimation () {
@@ -866,3 +886,69 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
866886 );
867887 }
868888}
889+
890+ // Hand coded defaults based on Material Design 2.
891+ class _CircularProgressIndicatorDefaultsM2 extends ProgressIndicatorThemeData {
892+ _CircularProgressIndicatorDefaultsM2 (this .context);
893+
894+ final BuildContext context;
895+ late final ColorScheme _colors = Theme .of (context).colorScheme;
896+
897+ @override
898+ Color get color => _colors.primary;
899+ }
900+
901+ class _LinearProgressIndicatorDefaultsM2 extends ProgressIndicatorThemeData {
902+ _LinearProgressIndicatorDefaultsM2 (this .context);
903+
904+ final BuildContext context;
905+ late final ColorScheme _colors = Theme .of (context).colorScheme;
906+
907+ @override
908+ Color get color => _colors.primary;
909+
910+ @override
911+ Color get linearTrackColor => _colors.background;
912+
913+ @override
914+ double get linearMinHeight => 4.0 ;
915+ }
916+
917+ // BEGIN GENERATED TOKEN PROPERTIES - ProgressIndicator
918+
919+ // Do not edit by hand. The code between the "BEGIN GENERATED" and
920+ // "END GENERATED" comments are generated from data in the Material
921+ // Design token database by the script:
922+ // dev/tools/gen_defaults/bin/gen_defaults.dart.
923+
924+ // Token database version: v0_132
925+
926+ class _CircularProgressIndicatorDefaultsM3 extends ProgressIndicatorThemeData {
927+ _CircularProgressIndicatorDefaultsM3 (this .context);
928+
929+ final BuildContext context;
930+ late final ColorScheme _colors = Theme .of (context).colorScheme;
931+
932+ static const double circularProgressIndicatorSize = 48.0 ;
933+
934+ @override
935+ Color get color => _colors.primary;
936+ }
937+
938+ class _LinearProgressIndicatorDefaultsM3 extends ProgressIndicatorThemeData {
939+ _LinearProgressIndicatorDefaultsM3 (this .context);
940+
941+ final BuildContext context;
942+ late final ColorScheme _colors = Theme .of (context).colorScheme;
943+
944+ @override
945+ Color get color => _colors.primary;
946+
947+ @override
948+ Color get linearTrackColor => _colors.surfaceVariant;
949+
950+ @override
951+ double get linearMinHeight => 4.0 ;
952+ }
953+
954+ // END GENERATED TOKEN PROPERTIES - ProgressIndicator
0 commit comments