我需要制作包含特定位置文本的自定义小部件(在 Flutter 中)。当我通过 TextPainter 绘制文本时,我将 TextAlign 设置为居中。文本仍然以左对齐方式绘制。我究竟做错了什么?
谢谢(我很抱歉我的英语不好)
TextSpan span = TextSpan(style: TextStyle(color: Colors.white, fontSize: textSize), text: 'T');
TextPainter tp = TextPainter(text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr);
tp.layout();
tp.paint(canvas, Offset(pos.x, pos.y));
Run Code Online (Sandbox Code Playgroud) flutter ×1