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 (将#修改为@)