drawText method
void
drawText(})
Implementation
void drawText(
String text,
Offset position,
{
TextStyle? style,
Alignment alignment = Alignment.centerLeft,
TextAlign textAlign = TextAlign.left,
int maxLines = 1,
}
) {
final textSpan = TextSpan(
text: text,
style: style,
);
final textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
textAlign: textAlign,
maxLines: maxLines,
);
textPainter.layout();
final double x, y;
if (alignment.x < 0) {
x = position.dx;
} else if (alignment.x > 0) {
x = position.dx - textPainter.width;
} else {
x = position.dx - textPainter.width * 0.5;
}
if (alignment.y < 0) {
y = position.dy - textPainter.height;
} else if (alignment.y > 0) {
y = position.dy + textPainter.height;
} else {
y = position.dy - textPainter.height * 0.5;
}
textPainter.paint(this, Offset(x, y));
}