Skip to content

Commit a7dd669

Browse files
author
Mohammad Ghalayini
authored
Add a borderRadius property to TableBorder (flutter#85946)
1 parent a67f618 commit a7dd669

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

packages/flutter/lib/src/rendering/table_border.dart

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TableBorder {
2323
this.left = BorderSide.none,
2424
this.horizontalInside = BorderSide.none,
2525
this.verticalInside = BorderSide.none,
26+
this.borderRadius = BorderRadius.zero,
2627
});
2728

2829
/// A uniform border with all sides the same color and width.
@@ -32,9 +33,10 @@ class TableBorder {
3233
Color color = const Color(0xFF000000),
3334
double width = 1.0,
3435
BorderStyle style = BorderStyle.solid,
36+
BorderRadius borderRadius = BorderRadius.zero,
3537
}) {
3638
final BorderSide side = BorderSide(color: color, width: width, style: style);
37-
return TableBorder(top: side, right: side, bottom: side, left: side, horizontalInside: side, verticalInside: side);
39+
return TableBorder(top: side, right: side, bottom: side, left: side, horizontalInside: side, verticalInside: side, borderRadius: borderRadius);
3840
}
3941

4042
/// Creates a border for a table where all the interior sides use the same
@@ -71,6 +73,9 @@ class TableBorder {
7173
/// The vertical interior sides of this border.
7274
final BorderSide verticalInside;
7375

76+
/// The [BorderRadius] to use when painting the corners of this border.
77+
final BorderRadius borderRadius;
78+
7479
/// The widths of the sides of this border represented as an [EdgeInsets].
7580
///
7681
/// This can be used, for example, with a [Padding] widget to inset a box by
@@ -256,7 +261,14 @@ class TableBorder {
256261
}
257262
}
258263
}
259-
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
264+
if(!isUniform || borderRadius == BorderRadius.zero)
265+
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
266+
else {
267+
final RRect outer = borderRadius.toRRect(rect);
268+
final RRect inner = outer.deflate(top.width);
269+
final Paint paint = Paint()..color = top.color;
270+
canvas.drawDRRect(outer, inner, paint);
271+
}
260272
}
261273

262274
@override
@@ -271,12 +283,13 @@ class TableBorder {
271283
&& other.bottom == bottom
272284
&& other.left == left
273285
&& other.horizontalInside == horizontalInside
274-
&& other.verticalInside == verticalInside;
286+
&& other.verticalInside == verticalInside
287+
&& other.borderRadius == borderRadius;
275288
}
276289

277290
@override
278-
int get hashCode => hashValues(top, right, bottom, left, horizontalInside, verticalInside);
291+
int get hashCode => hashValues(top, right, bottom, left, horizontalInside, verticalInside, borderRadius);
279292

280293
@override
281-
String toString() => 'TableBorder($top, $right, $bottom, $left, $horizontalInside, $verticalInside)';
294+
String toString() => 'TableBorder($top, $right, $bottom, $left, $horizontalInside, $verticalInside, $borderRadius)';
282295
}

packages/flutter/test/rendering/table_border_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ void main() {
124124

125125
test('TableBorder Object API', () {
126126
final String none = BorderSide.none.toString();
127-
expect(const TableBorder().toString(), 'TableBorder($none, $none, $none, $none, $none, $none)');
127+
final String zeroRadius = BorderRadius.zero.toString();
128+
expect(const TableBorder().toString(), 'TableBorder($none, $none, $none, $none, $none, $none, $zeroRadius)');
128129
});
130+
131+
test('TableBorder.all with a borderRadius', () {
132+
final TableBorder tableA = TableBorder.all(borderRadius: BorderRadius.circular(8.0));
133+
expect(tableA.borderRadius, BorderRadius.circular(8.0));
134+
});
135+
129136
}

packages/flutter/test/rendering/table_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,26 @@ void main() {
253253
layout(table, constraints: BoxConstraints.tight(const Size(800.0, 600.0)));
254254
expect(table.hasSize, true);
255255
});
256+
257+
test('Table paints a borderRadius', () {
258+
final RenderTable table = RenderTable(
259+
textDirection: TextDirection.ltr,
260+
border: TableBorder.all(borderRadius: BorderRadius.circular(8.0)),
261+
);
262+
layout(table);
263+
table.setFlatChildren(2, <RenderBox>[
264+
RenderPositionedBox(), RenderPositionedBox(),
265+
RenderPositionedBox(), RenderPositionedBox(),
266+
]);
267+
pumpFrame();
268+
expect(table, paints
269+
..path()
270+
..path()
271+
..drrect(
272+
outer: RRect.fromLTRBR(0.0, 0.0, 800.0, 0.0, const Radius.circular(8.0)),
273+
inner: RRect.fromLTRBR(1.0, 1.0, 799.0, -1.0, const Radius.circular(7.0)),
274+
)
275+
);
276+
});
277+
256278
}

0 commit comments

Comments
 (0)