Created
May 31, 2021 16:55
-
-
Save Indy9000/d2e15d431e746f41885200a79a0f620a to your computer and use it in GitHub Desktop.
animated-donut-chart-05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextPainter measureText( | |
String s, TextStyle style, double maxWidth, TextAlign align) { | |
final span = TextSpan(text: s, style: style); | |
final tp = TextPainter( | |
text: span, textAlign: align, textDirection: TextDirection.ltr); | |
// ellipsis: "..."); | |
tp.layout(minWidth: 0, maxWidth: maxWidth); | |
return tp; | |
} | |
Size drawTextCentered(Canvas canvas, Offset position, String text, | |
TextStyle style, double maxWidth, Function(Size sz) bgCb) { | |
final tp = measureText(text, style, maxWidth, TextAlign.center); | |
final pos = position + Offset(-tp.width / 2.0, -tp.height / 2.0); | |
bgCb(tp.size); | |
tp.paint(canvas, pos); | |
return tp.size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment