Skip to content

feat: Add radius to DividerThemeData. #169739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Add radius to DividerThemeData.
  • Loading branch information
StanleyCocos committed May 30, 2025
commit 4d7cfd4ef499f879424aff868d1682a09dfc44d2
9 changes: 5 additions & 4 deletions packages/flutter/lib/src/material/divider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ class Divider extends StatelessWidget {
/// {@endtemplate}
final double? endIndent;

/// {@template flutter.material.Divider.radius}
/// The amount of radius for the border of the divider.
///
/// {@template flutter.material.Divider.radius}
/// If this is null, then the default radius of [BoxDecoration] will be used.
/// If this is null, then [DividerThemeData.radius] is used. If that is
/// also null, then the default radius of [BoxDecoration] is used.
/// {@endtemplate}
final BorderRadiusGeometry? radius;

Expand Down Expand Up @@ -199,7 +200,7 @@ class Divider extends StatelessWidget {
height: thickness,
margin: EdgeInsetsDirectional.only(start: indent, end: endIndent),
decoration: BoxDecoration(
borderRadius: radius,
borderRadius: radius ?? dividerTheme.radius ?? defaults.radius,
border: Border(bottom: createBorderSide(context, color: color, width: thickness)),
),
),
Expand Down Expand Up @@ -324,7 +325,7 @@ class VerticalDivider extends StatelessWidget {
width: thickness,
margin: EdgeInsetsDirectional.only(top: indent, bottom: endIndent),
decoration: BoxDecoration(
borderRadius: radius,
borderRadius: radius ?? dividerTheme.radius ?? defaults.radius,
border: Border(left: Divider.createBorderSide(context, color: color, width: thickness)),
),
),
Expand Down
23 changes: 20 additions & 3 deletions packages/flutter/lib/src/material/divider_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ import 'theme.dart';
class DividerThemeData with Diagnosticable {
/// Creates a theme that can be used for [DividerTheme] or
/// [ThemeData.dividerTheme].
const DividerThemeData({this.color, this.space, this.thickness, this.indent, this.endIndent});
const DividerThemeData({
this.color,
this.space,
this.thickness,
this.indent,
this.endIndent,
this.radius,
});

/// The color of [Divider]s and [VerticalDivider]s, also
/// used between [ListTile]s, between rows in [DataTable]s, and so forth.
Expand All @@ -61,6 +68,11 @@ class DividerThemeData with Diagnosticable {
/// of [VerticalDivider].
final double? endIndent;

/// The border radius applied to the [Divider] or [VerticalDivider].
///
/// If non-null, this radius will be used to round the corners of the divider.
final BorderRadiusGeometry? radius;

/// Creates a copy of this object with the given fields replaced with the
/// new values.
DividerThemeData copyWith({
Expand All @@ -69,13 +81,15 @@ class DividerThemeData with Diagnosticable {
double? thickness,
double? indent,
double? endIndent,
BorderRadiusGeometry? radius,
}) {
return DividerThemeData(
color: color ?? this.color,
space: space ?? this.space,
thickness: thickness ?? this.thickness,
indent: indent ?? this.indent,
endIndent: endIndent ?? this.endIndent,
radius: radius ?? this.radius,
);
}

Expand All @@ -92,11 +106,12 @@ class DividerThemeData with Diagnosticable {
thickness: lerpDouble(a?.thickness, b?.thickness, t),
indent: lerpDouble(a?.indent, b?.indent, t),
endIndent: lerpDouble(a?.endIndent, b?.endIndent, t),
radius: BorderRadiusGeometry.lerp(a?.radius, b?.radius, t),
);
}

@override
int get hashCode => Object.hash(color, space, thickness, indent, endIndent);
int get hashCode => Object.hash(color, space, thickness, indent, endIndent, radius);

@override
bool operator ==(Object other) {
Expand All @@ -111,7 +126,8 @@ class DividerThemeData with Diagnosticable {
other.space == space &&
other.thickness == thickness &&
other.indent == indent &&
other.endIndent == endIndent;
other.endIndent == endIndent &&
other.radius == radius;
}

@override
Expand All @@ -122,6 +138,7 @@ class DividerThemeData with Diagnosticable {
properties.add(DoubleProperty('thickness', thickness, defaultValue: null));
properties.add(DoubleProperty('indent', indent, defaultValue: null));
properties.add(DoubleProperty('endIndent', endIndent, defaultValue: null));
properties.add(DiagnosticsProperty<BorderRadiusGeometry>('radius', radius, defaultValue: null));
}
}

Expand Down
41 changes: 41 additions & 0 deletions packages/flutter/test/material/divider_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
expect(dividerTheme.thickness, null);
expect(dividerTheme.indent, null);
expect(dividerTheme.endIndent, null);
expect(dividerTheme.radius, null);
});

testWidgets('Default DividerThemeData debugFillProperties', (WidgetTester tester) async {
Expand All @@ -42,6 +43,7 @@ void main() {
thickness: 4.0,
indent: 3.0,
endIndent: 2.0,
radius: BorderRadius.all(Radius.circular(20)),
).debugFillProperties(builder);

final List<String> description =
Expand All @@ -56,6 +58,7 @@ void main() {
'thickness: 4.0',
'indent: 3.0',
'endIndent: 2.0',
'radius: BorderRadius.circular(20.0)',
]);
});

Expand Down Expand Up @@ -100,6 +103,12 @@ void main() {
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.left, dividerRect.left + dividerTheme.indent!);
expect(lineRect.right, dividerRect.right - dividerTheme.endIndent!);

final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.topLeft, const Radius.circular(1));
expect(borderRadius.topRight, const Radius.circular(2));
expect(borderRadius.bottomLeft, const Radius.circular(3));
expect(borderRadius.bottomRight, const Radius.circular(4));
});

testWidgets('DividerTheme overrides defaults', (WidgetTester tester) async {
Expand Down Expand Up @@ -132,6 +141,7 @@ void main() {
thickness: thickness,
indent: indent,
endIndent: endIndent,
radius: BorderRadiusGeometry.all(Radius.circular(5)),
),
),
),
Expand All @@ -149,6 +159,12 @@ void main() {
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.left, dividerRect.left + indent);
expect(lineRect.right, dividerRect.right - endIndent);

final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.topLeft, const Radius.circular(5));
expect(borderRadius.topRight, const Radius.circular(5));
expect(borderRadius.bottomLeft, const Radius.circular(5));
expect(borderRadius.bottomRight, const Radius.circular(5));
});
});

Expand Down Expand Up @@ -197,6 +213,12 @@ void main() {
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.top, dividerRect.top + dividerTheme.indent!);
expect(lineRect.bottom, dividerRect.bottom - dividerTheme.endIndent!);

final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.topLeft, const Radius.circular(1));
expect(borderRadius.topRight, const Radius.circular(2));
expect(borderRadius.bottomLeft, const Radius.circular(3));
expect(borderRadius.bottomRight, const Radius.circular(4));
});

testWidgets('DividerTheme overrides defaults', (WidgetTester tester) async {
Expand Down Expand Up @@ -232,6 +254,7 @@ void main() {
thickness: thickness,
indent: indent,
endIndent: endIndent,
radius: BorderRadiusGeometry.all(Radius.circular(5)),
),
),
),
Expand All @@ -250,6 +273,12 @@ void main() {
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.top, dividerRect.top + indent);
expect(lineRect.bottom, dividerRect.bottom - endIndent);

final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.topLeft, const Radius.circular(5));
expect(borderRadius.topRight, const Radius.circular(5));
expect(borderRadius.bottomLeft, const Radius.circular(5));
expect(borderRadius.bottomRight, const Radius.circular(5));
});
});

Expand Down Expand Up @@ -290,6 +319,12 @@ void main() {
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, theme.thickness);
expect(decoration.border!.bottom.color, theme.color);

final BorderRadius borderRadius = decoration.borderRadius! as BorderRadius;
expect(borderRadius.topLeft, const Radius.circular(1));
expect(borderRadius.topRight, const Radius.circular(2));
expect(borderRadius.bottomLeft, const Radius.circular(3));
expect(borderRadius.bottomRight, const Radius.circular(4));
});
});

Expand Down Expand Up @@ -329,5 +364,11 @@ DividerThemeData _dividerTheme() {
thickness: 2.0,
indent: 7.0,
endIndent: 5.0,
radius: BorderRadiusGeometry.only(
topLeft: Radius.circular(1),
topRight: Radius.circular(2),
bottomLeft: Radius.circular(3),
bottomRight: Radius.circular(4),
),
);
}