我正在CustomPainter根据以下问题使用 flutter 进行绘制:Flutter: How to Paint an Icon on Canvas?
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));
Run Code Online (Sandbox Code Playgroud)
这适用于材料设计图标。不过,我想使用相同的技术来绘制 Font Awesome 图标。我正在使用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));
Run Code Online (Sandbox Code Playgroud)
我从 IDE 收到一条消息,指出“未为类 'Icon' 定义 getter 'codePoint'”。请问我该如何解决这个问题?