paintText function
Paints the specified title
on the canvas
at the given cartesian2D
position.
The textStyle
parameter is optional and can be used to customize the text style.
The size
parameter represents the size of the canvas.
Implementation
void paintText(String title, material.TextStyle? textStyle, Offset cartesian2D,
Size size, Canvas canvas) {
final defaultTextPaint = Paint()
..color = material.Colors.blue.withOpacity(0.7)
..strokeWidth = 25
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..style = PaintingStyle.stroke;
final defaultTextStyle = material.TextStyle(
background: defaultTextPaint,
color: material.Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
);
final textSpan = material.TextSpan(
text: title,
style: textStyle ?? defaultTextStyle,
);
final textPainter = material.TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
);
textPainter.layout(
minWidth: 0,
maxWidth: size.width,
);
final offset = Offset(
cartesian2D.dx - textPainter.width / 2,
cartesian2D.dy -
20 -
textPainter.height / 2); // Position where the text will start
textPainter.paint(canvas, offset);
}