paintString static method

void paintString(
  1. Canvas canvas,
  2. Offset point,
  3. String text, {
  4. double fontSize = 12,
  5. Color color = Colors.black,
  6. double rotateAngle = 0,
})

绘制字符串
point 绘制中点
text 显示文本
fontSize 文本大小
color 文本颜色
rotateAngle 旋转角度

Implementation

static void paintString(
  Canvas canvas,
  Offset point,
  String text, {
  double fontSize = 12,
  Color color = Colors.black,
  double rotateAngle = 0,
}) {
  TextPainter textPainter = TextPainter(
      textAlign: TextAlign.center, textDirection: TextDirection.rtl);

  // 绘制标题
  textPainter.text = TextSpan(
      text: text,
      style: TextStyle(
          color: color, fontFamily: 'Times New Roman', fontSize: fontSize));
  textPainter.layout();
  canvas.save();
  canvas.rotate(-rotateAngle);
  textPainter.paint(
      canvas,
      Offset(point.dx - textPainter.width * 0.5,
          point.dy - textPainter.height * 0.5));
  canvas.restore();
}