diff --git a/packages/flutter/lib/src/material/divider.dart b/packages/flutter/lib/src/material/divider.dart index 3a0ac9868d..c9229eb24c 100644 --- a/packages/flutter/lib/src/material/divider.dart +++ b/packages/flutter/lib/src/material/divider.dart @@ -58,11 +58,18 @@ class Divider extends StatelessWidget { /// /// The [height], [thickness], [indent], and [endIndent] must be null or /// non-negative. - const Divider({super.key, this.height, this.thickness, this.indent, this.endIndent, this.color}) - : assert(height == null || height >= 0.0), - assert(thickness == null || thickness >= 0.0), - assert(indent == null || indent >= 0.0), - assert(endIndent == null || endIndent >= 0.0); + const Divider({ + super.key, + this.height, + this.thickness, + this.indent, + this.endIndent, + this.color, + this.radius, + }) : assert(height == null || height >= 0.0), + assert(thickness == null || thickness >= 0.0), + assert(indent == null || indent >= 0.0), + assert(endIndent == null || endIndent >= 0.0); /// The divider's height extent. /// @@ -94,6 +101,11 @@ class Divider extends StatelessWidget { /// also null, then this defaults to 0.0. final double? endIndent; + /// The amount of radius for the border of the divider. + /// + /// If this is null, then the default radius of [BoxDecoration] will be used. + final BorderRadiusGeometry? radius; + /// The color to use when painting the line. /// /// If this is null, then the [DividerThemeData.color] is used. If that is @@ -177,6 +189,7 @@ class Divider extends StatelessWidget { height: thickness, margin: EdgeInsetsDirectional.only(start: indent, end: endIndent), decoration: BoxDecoration( + borderRadius: radius, border: Border(bottom: createBorderSide(context, color: color, width: thickness)), ), ), @@ -227,6 +240,7 @@ class VerticalDivider extends StatelessWidget { this.indent, this.endIndent, this.color, + this.radius, }) : assert(width == null || width >= 0.0), assert(thickness == null || thickness >= 0.0), assert(indent == null || indent >= 0.0), @@ -277,6 +291,11 @@ class VerticalDivider extends StatelessWidget { /// {@end-tool} final Color? color; + /// The amount of radius for the border of the divider. + /// + /// If this is null, then the default radius of [BoxDecoration] will be used. + final BorderRadiusGeometry? radius; + @override Widget build(BuildContext context) { final ThemeData theme = Theme.of(context); @@ -295,6 +314,7 @@ class VerticalDivider extends StatelessWidget { width: thickness, margin: EdgeInsetsDirectional.only(top: indent, bottom: endIndent), decoration: BoxDecoration( + borderRadius: radius, border: Border(left: Divider.createBorderSide(context, color: color, width: thickness)), ), ), diff --git a/packages/flutter/test/material/divider_test.dart b/packages/flutter/test/material/divider_test.dart index 7dec6fa0c7..040df20f19 100644 --- a/packages/flutter/test/material/divider_test.dart +++ b/packages/flutter/test/material/divider_test.dart @@ -40,6 +40,22 @@ void main() { expect(decoration.border!.bottom.width, 5.0); }); + testWidgets('Divider custom radius', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center(child: Divider(radius: BorderRadius.circular(5))), + ), + ); + final Container container = tester.widget(find.byType(Container)); + final BoxDecoration decoration = container.decoration! as BoxDecoration; + final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius; + expect(borderRadius.bottomLeft, const Radius.circular(5)); + expect(borderRadius.bottomRight, const Radius.circular(5)); + expect(borderRadius.topLeft, const Radius.circular(5)); + expect(borderRadius.topRight, const Radius.circular(5)); + }); + testWidgets('Horizontal divider custom indentation', (WidgetTester tester) async { const double customIndent = 10.0; Rect dividerRect; @@ -183,6 +199,22 @@ void main() { expect(lineRect.bottom, dividerRect.bottom - customIndent); }); + testWidgets('VerticalDivider custom radius', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Center(child: VerticalDivider(radius: BorderRadius.circular(5))), + ), + ); + final Container container = tester.widget(find.byType(Container)); + final BoxDecoration decoration = container.decoration! as BoxDecoration; + final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius; + expect(borderRadius.bottomLeft, const Radius.circular(5)); + expect(borderRadius.bottomRight, const Radius.circular(5)); + expect(borderRadius.topLeft, const Radius.circular(5)); + expect(borderRadius.topRight, const Radius.circular(5)); + }); + // Regression test for https://github.com/flutter/flutter/issues/39533 testWidgets('createBorderSide does not throw exception with null context', ( WidgetTester tester,