Flutter:如何在画布上绘制图标?
我正在使用CustomPainter
这样在Flutter中进行绘制:
@overridevoid paint(Canvas canvas, Size size) {
canvas.drawRect(...);
canvas.drawImage(...);
...
}
如何绘制Icon
的canvas
?
回答:
创建Paragraph
包含正确字体的代码点,根据需要设置样式,然后绘制。
final icon = Icons.add;var builder = ui.ParagraphBuilder(ui.ParagraphStyle(
fontFamily: icon.fontFamily,
))
..addText(String.fromCharCode(icon.codePoint));
var para = builder.build();
para.layout(const ui.ParagraphConstraints(width: 60));
canvas.drawParagraph(para, const Offset(20, 20));
以上是 Flutter:如何在画布上绘制图标? 的全部内容, 来源链接: utcz.com/qa/418315.html