Flutter:如何在画布上绘制图标?

我正在使用CustomPainter这样在Flutter中进行绘制:

@override

void paint(Canvas canvas, Size size) {

canvas.drawRect(...);

canvas.drawImage(...);

...

}

如何绘制Iconcanvas

回答:

创建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

回到顶部