Flutter:如何绘制 Font Awesome 图标?
Flutter: how to paint a Font Awesome Icon?
我正在使用 CustomPainter
根据这个问题在 flutter 中绘制:
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));
这适用于 Material 设计图标。但是我想使用相同的技术来绘制 Font Awesome 图标。我正在使用 font_awesome_flutter 8.5.0 package,这是我的代码:
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 的消息说 "The getter 'codePoint' isn't defined for the class 'Icon'"。请问我该如何解决这个问题?
感谢@pskink 帮我找出答案:
final fishCodePoint = FontAwesomeIcons.fish.codePoint;
print('The codePoint is $fishCodePoint');
final fishFontPackage = FontAwesomeIcons.fish.fontPackage;
print('The fontPackage is $fishFontPackage');
final fishFontFamily = FontAwesomeIcons.fish.fontFamily;
print('The fontFamily is $fishFontFamily');
TextPainter textPainter = TextPainter(textDirection: TextDirection.rtl);
textPainter.text = TextSpan(
text: String.fromCharCode(fishCodePoint),
style: TextStyle(
fontSize: 40.0,
fontFamily: fishFontFamily,
package: fishFontPackage));
textPainter.paint(canvas, Offset(50.0, 50.0));
我正在使用 CustomPainter
根据这个问题在 flutter 中绘制:
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));
这适用于 Material 设计图标。但是我想使用相同的技术来绘制 Font Awesome 图标。我正在使用 font_awesome_flutter 8.5.0 package,这是我的代码:
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 的消息说 "The getter 'codePoint' isn't defined for the class 'Icon'"。请问我该如何解决这个问题?
感谢@pskink 帮我找出答案:
final fishCodePoint = FontAwesomeIcons.fish.codePoint;
print('The codePoint is $fishCodePoint');
final fishFontPackage = FontAwesomeIcons.fish.fontPackage;
print('The fontPackage is $fishFontPackage');
final fishFontFamily = FontAwesomeIcons.fish.fontFamily;
print('The fontFamily is $fishFontFamily');
TextPainter textPainter = TextPainter(textDirection: TextDirection.rtl);
textPainter.text = TextSpan(
text: String.fromCharCode(fishCodePoint),
style: TextStyle(
fontSize: 40.0,
fontFamily: fishFontFamily,
package: fishFontPackage));
textPainter.paint(canvas, Offset(50.0, 50.0));