如何解决Flutter TextPainter-圆内的中心字符
我需要画一个圆圈+圆圈内一个字符。角色应该位于我的圈子的中心,该怎么做?我的代码:
class CirclePainter extends CustomPainter {
String text;
@override
void paint(Canvas canvas,Size size) {
var paint1 = Paint()
..color = Color(Colors.blueGrey.value + 100*text.codeUnitAt(0))
..style = PaintingStyle.fill;
canvas.drawCircle(Offset(0,0),20,paint1);
TextSpan span = new TextSpan(
text: text.toUpperCase(),style: TextStyle(
fontFamily: AppTheme.fontName,fontWeight: FontWeight.w400,fontSize: 22,color: Colors.white,));
TextPainter tp = new TextPainter(
text: span,textAlign: TextAlign.center,textDirection: TextDirection.ltr);
tp.layout(minWidth: 20,maxWidth: 20);
tp.paint(canvas,Offset(-10.0,-10.0));
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
使用我目前的方法,某些字母仍未正确定位在我的圆内(水平和垂直方向)。什么是有效的解决方案?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。