diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index ed71d24c00..6669850f2b 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -145,6 +145,7 @@ class _LinearProgressIndicatorPainter extends CustomPainter { this.value, required this.animationValue, required this.textDirection, + required this.indicatorBorderRadius, }); final Color backgroundColor; @@ -152,6 +153,7 @@ class _LinearProgressIndicatorPainter extends CustomPainter { final double? value; final double animationValue; final TextDirection textDirection; + final BorderRadiusGeometry indicatorBorderRadius; // The indeterminate progress animation displays two lines whose leading (head) // and trailing (tail) endpoints are defined by the following four curves. @@ -181,7 +183,6 @@ class _LinearProgressIndicatorPainter extends CustomPainter { final Paint paint = Paint() ..color = backgroundColor ..style = PaintingStyle.fill; - canvas.drawRect(Offset.zero & size, paint); paint.color = valueColor; @@ -197,7 +198,14 @@ class _LinearProgressIndicatorPainter extends CustomPainter { case TextDirection.ltr: left = x; } - canvas.drawRect(Offset(left, 0.0) & Size(width, size.height), paint); + + final Rect rect = Offset(left, 0.0) & Size(width, size.height); + if (indicatorBorderRadius != BorderRadius.zero) { + final RRect rrect = indicatorBorderRadius.resolve(textDirection).toRRect(rect); + canvas.drawRRect(rrect, paint); + } else { + canvas.drawRect(rect, paint); + } } if (value != null) { @@ -220,7 +228,8 @@ class _LinearProgressIndicatorPainter extends CustomPainter { || oldPainter.valueColor != valueColor || oldPainter.value != value || oldPainter.animationValue != animationValue - || oldPainter.textDirection != textDirection; + || oldPainter.textDirection != textDirection + || oldPainter.indicatorBorderRadius != indicatorBorderRadius; } } @@ -279,6 +288,7 @@ class LinearProgressIndicator extends ProgressIndicator { this.minHeight, super.semanticsLabel, super.semanticsValue, + this.borderRadius = BorderRadius.zero, }) : assert(minHeight == null || minHeight > 0); /// {@template flutter.material.LinearProgressIndicator.trackColor} @@ -301,6 +311,12 @@ class LinearProgressIndicator extends ProgressIndicator { /// {@endtemplate} final double? minHeight; + /// The border radius of both the indicator and the track. + /// + /// By default it is [BorderRadius.zero], which produces a rectangular shape + /// with a rectangular indicator. + final BorderRadiusGeometry borderRadius; + @override State createState() => _LinearProgressIndicatorState(); } @@ -352,6 +368,14 @@ class _LinearProgressIndicatorState extends State with return widget._buildSemanticsWrapper( context: context, child: Container( + // Clip is only needed with indeterminate progress indicators + clipBehavior: (widget.borderRadius != BorderRadius.zero && widget.value == null) + ? Clip.antiAlias + : Clip.none, + decoration: ShapeDecoration( + color: trackColor, + shape: RoundedRectangleBorder(borderRadius: widget.borderRadius), + ), constraints: BoxConstraints( minWidth: double.infinity, minHeight: minHeight, @@ -363,6 +387,7 @@ class _LinearProgressIndicatorState extends State with value: widget.value, // may be null animationValue: animationValue, // ignored if widget.value is not null textDirection: textDirection, + indicatorBorderRadius: widget.borderRadius, ), ), ), diff --git a/packages/flutter/test/material/progress_indicator_test.dart b/packages/flutter/test/material/progress_indicator_test.dart index 8419d7c298..c609c04956 100644 --- a/packages/flutter/test/material/progress_indicator_test.dart +++ b/packages/flutter/test/material/progress_indicator_test.dart @@ -465,6 +465,41 @@ void main() { expect(find.byType(CircularProgressIndicator), paints..arc(strokeCap: StrokeCap.round)); }); + testWidgets('LinearProgressIndicator with indicatorBorderRadius', (WidgetTester tester) async { + await tester.pumpWidget( + Theme( + data: theme, + child: const Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + width: 100.0, + height: 4.0, + child: LinearProgressIndicator( + value: 0.25, + borderRadius: BorderRadius.all(Radius.circular(10)), + ), + ), + ), + ), + ), + ); + expect( + find.byType(LinearProgressIndicator), + paints + ..rrect( + rrect: RRect.fromLTRBR(0.0, 0.0, 100.0, 4.0, const Radius.circular(10.0)), + ) + ..rrect( + rrect: RRect.fromRectAndRadius( + const Rect.fromLTRB(0.0, 0.0, 25.0, 4.0), + const Radius.circular(10.0), + ), + ), + ); + expect(tester.binding.transientCallbackCount, 0); + }); + testWidgets('CircularProgressIndicator paint colors', (WidgetTester tester) async { const Color green = Color(0xFF00FF00); const Color blue = Color(0xFF0000FF);