Add a borderRadius property to TableBorder (#85946)
This commit is contained in:
committed by
GitHub
parent
a67f618a29
commit
a7dd6698fd
@@ -23,6 +23,7 @@ class TableBorder {
|
||||
this.left = BorderSide.none,
|
||||
this.horizontalInside = BorderSide.none,
|
||||
this.verticalInside = BorderSide.none,
|
||||
this.borderRadius = BorderRadius.zero,
|
||||
});
|
||||
|
||||
/// A uniform border with all sides the same color and width.
|
||||
@@ -32,9 +33,10 @@ class TableBorder {
|
||||
Color color = const Color(0xFF000000),
|
||||
double width = 1.0,
|
||||
BorderStyle style = BorderStyle.solid,
|
||||
BorderRadius borderRadius = BorderRadius.zero,
|
||||
}) {
|
||||
final BorderSide side = BorderSide(color: color, width: width, style: style);
|
||||
return TableBorder(top: side, right: side, bottom: side, left: side, horizontalInside: side, verticalInside: side);
|
||||
return TableBorder(top: side, right: side, bottom: side, left: side, horizontalInside: side, verticalInside: side, borderRadius: borderRadius);
|
||||
}
|
||||
|
||||
/// Creates a border for a table where all the interior sides use the same
|
||||
@@ -71,6 +73,9 @@ class TableBorder {
|
||||
/// The vertical interior sides of this border.
|
||||
final BorderSide verticalInside;
|
||||
|
||||
/// The [BorderRadius] to use when painting the corners of this border.
|
||||
final BorderRadius borderRadius;
|
||||
|
||||
/// The widths of the sides of this border represented as an [EdgeInsets].
|
||||
///
|
||||
/// This can be used, for example, with a [Padding] widget to inset a box by
|
||||
@@ -256,7 +261,14 @@ class TableBorder {
|
||||
}
|
||||
}
|
||||
}
|
||||
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
|
||||
if(!isUniform || borderRadius == BorderRadius.zero)
|
||||
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
|
||||
else {
|
||||
final RRect outer = borderRadius.toRRect(rect);
|
||||
final RRect inner = outer.deflate(top.width);
|
||||
final Paint paint = Paint()..color = top.color;
|
||||
canvas.drawDRRect(outer, inner, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -271,12 +283,13 @@ class TableBorder {
|
||||
&& other.bottom == bottom
|
||||
&& other.left == left
|
||||
&& other.horizontalInside == horizontalInside
|
||||
&& other.verticalInside == verticalInside;
|
||||
&& other.verticalInside == verticalInside
|
||||
&& other.borderRadius == borderRadius;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hashValues(top, right, bottom, left, horizontalInside, verticalInside);
|
||||
int get hashCode => hashValues(top, right, bottom, left, horizontalInside, verticalInside, borderRadius);
|
||||
|
||||
@override
|
||||
String toString() => 'TableBorder($top, $right, $bottom, $left, $horizontalInside, $verticalInside)';
|
||||
String toString() => 'TableBorder($top, $right, $bottom, $left, $horizontalInside, $verticalInside, $borderRadius)';
|
||||
}
|
||||
|
||||
@@ -124,6 +124,13 @@ void main() {
|
||||
|
||||
test('TableBorder Object API', () {
|
||||
final String none = BorderSide.none.toString();
|
||||
expect(const TableBorder().toString(), 'TableBorder($none, $none, $none, $none, $none, $none)');
|
||||
final String zeroRadius = BorderRadius.zero.toString();
|
||||
expect(const TableBorder().toString(), 'TableBorder($none, $none, $none, $none, $none, $none, $zeroRadius)');
|
||||
});
|
||||
|
||||
test('TableBorder.all with a borderRadius', () {
|
||||
final TableBorder tableA = TableBorder.all(borderRadius: BorderRadius.circular(8.0));
|
||||
expect(tableA.borderRadius, BorderRadius.circular(8.0));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -253,4 +253,26 @@ void main() {
|
||||
layout(table, constraints: BoxConstraints.tight(const Size(800.0, 600.0)));
|
||||
expect(table.hasSize, true);
|
||||
});
|
||||
|
||||
test('Table paints a borderRadius', () {
|
||||
final RenderTable table = RenderTable(
|
||||
textDirection: TextDirection.ltr,
|
||||
border: TableBorder.all(borderRadius: BorderRadius.circular(8.0)),
|
||||
);
|
||||
layout(table);
|
||||
table.setFlatChildren(2, <RenderBox>[
|
||||
RenderPositionedBox(), RenderPositionedBox(),
|
||||
RenderPositionedBox(), RenderPositionedBox(),
|
||||
]);
|
||||
pumpFrame();
|
||||
expect(table, paints
|
||||
..path()
|
||||
..path()
|
||||
..drrect(
|
||||
outer: RRect.fromLTRBR(0.0, 0.0, 800.0, 0.0, const Radius.circular(8.0)),
|
||||
inner: RRect.fromLTRBR(1.0, 1.0, 799.0, -1.0, const Radius.circular(7.0)),
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user