dramaticlook
dramaticlook

Reputation: 713

Using Flutter, how can I paint text on canvas with rotation

I am trying to point a text over a given canvas and I can not find any option to paint this text with an angle so that it will be tilted.

void drawText(Canvas canvas, Offset center, String text, Color color,
Color bgColor, double fontSize) {
TextSpan span = new TextSpan(
  style: new TextStyle(
      color: color,
      backgroundColor: bgColor,
      fontWeight: FontWeight.bold,
      fontSize: fontSize),
  text: text);
  TextPainter tp = new TextPainter(
      text: span,
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr);
   tp.layout();
   tp.paint(canvas, center);
}

I have this function which is working fine left to right in an ordinary way but how can I rotate it with an angle? For reference you can see the image. I want to do it like the highlighted text which is rotated.

I am aware of the fact that we can do it using widgets like a button but how about a canvas? Any help is appreciated, Thanksenter image description here

Upvotes: 0

Views: 581

Answers (1)

DipsySu
DipsySu

Reputation: 21

Transform.rotate(
        angle: pi/2,
      child: customWeiget,
    );

Upvotes: 1

Related Questions