paint method
Paints the border within the given Rect on the given Canvas.
The textDirection
argument must be provided and non-null if the border
has a text direction dependency (for example if it is expressed in terms
of "start" and "end" instead of "left" and "right"). It may be null if
the border will not need the text direction to paint itself.
Implementation
@override
void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {
const lineSize = 30;
final width = rect.width;
final borderWidthSize = width * 10 / 100;
final height = rect.height;
const borderHeightSize =
600; // redusing this will increase the overlay height of scanner
final borderSize = Size(borderWidthSize / 2, borderHeightSize / 2);
var paint = Paint()
..color = overlayColor
..style = PaintingStyle.fill;
canvas
..drawRect(
Rect.fromLTRB(rect.left, rect.top - 100, rect.right,
borderSize.height + rect.top - 100),
paint,
)
..drawRect(
Rect.fromLTRB(rect.left, rect.bottom - borderSize.height - 100,
rect.right, rect.bottom - 100),
paint,
)
..drawRect(
Rect.fromLTRB(
rect.left,
rect.top + borderSize.height - 100,
rect.left + borderSize.width,
rect.bottom - borderSize.height - 100),
paint,
)
..drawRect(
Rect.fromLTRB(
rect.right - borderSize.width,
rect.top + borderSize.height - 100,
rect.right,
rect.bottom - borderSize.height - 100),
paint,
);
paint = Paint()
..color = borderColor
..style = PaintingStyle.stroke
..strokeWidth = borderWidth;
final borderOffset = borderWidth / 3;
final realReact = Rect.fromLTRB(
borderSize.width + borderOffset,
borderSize.height + borderOffset + rect.top,
width - borderSize.width - borderOffset,
height - borderSize.height - borderOffset + rect.top);
//Draw top right corner
canvas
..drawPath(
Path()
..moveTo(realReact.right, realReact.top - 100)
..lineTo(realReact.right, realReact.top - 100 + lineSize),
paint)
..drawPath(
Path()
..moveTo(realReact.right, realReact.top - 100)
..lineTo(realReact.right - lineSize, realReact.top - 100),
paint)
..drawPoints(
PointMode.points,
[Offset(realReact.right, realReact.top - 100)],
paint,
)
//Draw top left corner
..drawPath(
Path()
..moveTo(realReact.left, realReact.top - 100)
..lineTo(realReact.left, realReact.top - 100 + lineSize),
paint)
..drawPath(
Path()
..moveTo(realReact.left, realReact.top - 100)
..lineTo(realReact.left + lineSize, realReact.top - 100),
paint)
..drawPoints(
PointMode.points,
[Offset(realReact.left, realReact.top - 100)],
paint,
)
//Draw bottom right corner
..drawPath(
Path()
..moveTo(realReact.right, realReact.bottom - 100)
..lineTo(realReact.right, realReact.bottom - 100 - lineSize),
paint)
..drawPath(
Path()
..moveTo(realReact.right, realReact.bottom - 100)
..lineTo(realReact.right - lineSize, realReact.bottom - 100),
paint)
..drawPoints(
PointMode.points,
[Offset(realReact.right, realReact.bottom - 100)],
paint,
)
//Draw bottom left corner
..drawPath(
Path()
..moveTo(realReact.left, realReact.bottom - 100)
..lineTo(realReact.left, realReact.bottom - 100 - lineSize),
paint)
..drawPath(
Path()
..moveTo(realReact.left, realReact.bottom - 100)
..lineTo(realReact.left + lineSize, realReact.bottom - 100),
paint)
..drawPoints(
PointMode.points,
[Offset(realReact.left, realReact.bottom - 100)],
paint,
);
}