paintTxBorder function
void
paintTxBorder(
- Canvas canvas,
- Rect rect, {
- TxBorderSide? top,
- TxBorderSide? right,
- TxBorderSide? bottom,
- TxBorderSide? left,
Implementation
void paintTxBorder(
Canvas canvas,
Rect rect, {
TxBorderSide? top,
TxBorderSide? right,
TxBorderSide? bottom,
TxBorderSide? left,
}) {
top ??= TxBorderSide.none;
right ??= TxBorderSide.none;
bottom ??= TxBorderSide.none;
left ??= TxBorderSide.none;
final Paint paint = Paint()
..strokeWidth = 0.0
..style = PaintingStyle.stroke;
final Path path = Path();
switch (top.style) {
case BorderStyle.solid:
if (top.width == 0.0) {
break;
}
paint.color = top.color;
path.reset();
if (top.dashPattern == null) {
path.moveTo(rect.left, rect.top);
path.lineTo(rect.right, rect.top);
path.lineTo(rect.right - right.width, rect.top + top.width);
path.lineTo(rect.left + left.width, rect.top + top.width);
paint
..style = PaintingStyle.fill
..shader = top.gradient?.createShader(path.getBounds())
..strokeWidth = 0.0;
canvas.drawPath(path, paint);
} else {
path.moveTo(rect.left + left.width, rect.top + top.width / 2);
path.lineTo(rect.right - right.width, rect.top + top.width / 2);
paint
..shader = top.gradient?.createShader(path.getBounds())
..strokeWidth = top.width;
DashedPainter(top.dashPattern!).paint(canvas, path, paint);
}
break;
case BorderStyle.none:
break;
}
switch (right.style) {
case BorderStyle.solid:
if (right.width == 0.0) {
break;
}
paint.color = right.color;
path.reset();
if (right.dashPattern == null) {
path.moveTo(rect.right, rect.top);
path.lineTo(rect.right, rect.bottom);
path.lineTo(rect.right - right.width, rect.bottom - bottom.width);
path.lineTo(rect.right - right.width, rect.top + top.width);
paint
..style = PaintingStyle.fill
..shader = right.gradient?.createShader(path.getBounds())
..strokeWidth = 0.0;
canvas.drawPath(path, paint);
} else {
path.moveTo(rect.right - right.width / 2, rect.top + top.width);
path.lineTo(rect.right - right.width / 2, rect.bottom - bottom.width);
paint
..shader = right.gradient?.createShader(path.getBounds())
..style = PaintingStyle.stroke
..strokeWidth = right.width;
DashedPainter(right.dashPattern!).paint(canvas, path, paint);
}
break;
case BorderStyle.none:
break;
}
switch (bottom.style) {
case BorderStyle.solid:
if (bottom.width == 0.0) {
break;
}
paint.color = bottom.color;
path.reset();
if (bottom.dashPattern == null) {
path.moveTo(rect.right, rect.bottom);
path.lineTo(rect.left, rect.bottom);
path.lineTo(rect.left + left.width, rect.bottom - bottom.width);
path.lineTo(rect.right - right.width, rect.bottom - bottom.width);
paint
..style = PaintingStyle.fill
..shader = bottom.gradient?.createShader(path.getBounds())
..strokeWidth = 0.0;
canvas.drawPath(path, paint);
} else {
path.moveTo(rect.right - right.width, rect.bottom - bottom.width / 2);
path.lineTo(rect.left + left.width, rect.bottom - bottom.width / 2);
paint
..shader = bottom.gradient?.createShader(path.getBounds())
..style = PaintingStyle.stroke
..strokeWidth = bottom.width;
DashedPainter(bottom.dashPattern!).paint(canvas, path, paint);
}
break;
case BorderStyle.none:
break;
}
switch (left.style) {
case BorderStyle.solid:
if (left.width == 0.0) {
break;
}
paint.color = left.color;
path.reset();
if (left.dashPattern == null) {
path.moveTo(rect.left, rect.bottom);
path.lineTo(rect.left, rect.top);
path.lineTo(rect.left + left.width, rect.top + top.width);
path.lineTo(rect.left + left.width, rect.bottom - bottom.width);
paint
..style = PaintingStyle.fill
..shader = left.gradient?.createShader(path.getBounds())
..strokeWidth = 0.0;
canvas.drawPath(path, paint);
} else {
path.moveTo(rect.left + left.width / 2, rect.bottom - bottom.width);
path.lineTo(rect.left + left.width / 2, rect.top + top.width);
paint
..shader = left.gradient?.createShader(path.getBounds())
..style = PaintingStyle.stroke
..strokeWidth = left.width;
DashedPainter(left.dashPattern!).paint(canvas, path, paint);
}
break;
case BorderStyle.none:
break;
}
}