CustomPainter
根据这个问题,我正在使用颤振来绘制:颤振:如何在画布上绘制图标?
final icon = Icons.cake;
TextPainter textPainter = TextPainter(textDirection: TextDirection.rtl);
textPainter.text = TextSpan(
text: String.fromCharCode(icon.codePoint),
style: TextStyle(fontSize: 20.0, fontFamily: icon.fontFamily));
textPainter.layout();
textPainter.paint(canvas, Offset(200.0, 200.0));
这适用于材料设计图标。但是我想使用相同的技术来绘制 Font Awesome Icons。我正在使用font_awesome_flutter 8.5.0 包,这是我的代码:
final icon = Icon(FontAwesomeIcons.fish, size: 20, color: Colors.teal[700]);
TextPainter textPainter = TextPainter(textDirection: TextDirection.rtl);
textPainter.text = TextSpan(
text: String.fromCharCode(icon.codePoint),
style: TextStyle(fontSize: 20.0, fontFamily: icon.fontFamily));
textPainter.layout();
textPainter.paint(canvas, Offset(200.0, 200.0));
我从 IDE 收到一条消息,说“没有为类 'Icon' 定义 getter 'codePoint'”。请问我该如何解决这个问题?