0

Based on this SO question, I tried to draw a CupertinoIcon on a Canvas:

final icon = CupertinoIcons.add;
TextPainter textPainter = TextPainter( 
             textDirection: TextDirection.ltr 
             );
textPainter.text = TextSpan(
    text: String.fromCharCode( 
             icon.codePoint 
             ),
    style: TextStyle(
             fontSize: 40.0,
             fontFamily: icon.fontFamily 
             )
);
textPainter.layout();
textPainter.paint( canvas, Offset( params.x, params.y ) );

Note that the code is fully generic, since it uses properties like codePoint of the CupertinoIcon.

While this code renders the other painter commands, the code unfortunately renders a placeholder of the icon in Google Chrome:

enter image description here

How do I make the icon appear?

SteAp
  • 11,853
  • 10
  • 53
  • 88

1 Answers1

0

The icon appears, as soon as the package parameter gets added to TextStyle:

TextStyle(
  fontSize:   60.0,
  fontFamily: icon.fontFamily, 
  color:      Colors.red, 
  package:    icon.fontPackage  // Need to make the icon appear
)

The documentation says this:

To use a font family defined in a package, the package argument must be provided.
SteAp
  • 11,853
  • 10
  • 53
  • 88