我正在使用CustomPainter这样在Flutter中进行绘制:
CustomPainter
@override void paint(Canvas canvas, Size size) { canvas.drawRect(...); canvas.drawImage(...); ... }
如何绘制Icon的canvas?
Icon
canvas
创建Paragraph包含正确字体的代码点,根据需要设置样式,然后绘制。
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));