一尘不染

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

flutter

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

@override
void paint(Canvas canvas, Size size) {
  canvas.drawRect(...);
  canvas.drawImage(...);
  ...
}

如何绘制Iconcanvas


阅读 543

收藏
2020-08-13

共1个答案

一尘不染

创建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));
2020-08-13