【问题标题】:Make CupertinoIcon render and not show placeholder使 CupertinoIcon 渲染而不显示占位符
【发布时间】:2021-05-21 21:35:32
【问题描述】:

基于this SO question,我尝试在Canvas上绘制CupertinoIcon

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 ) );

请注意,代码是完全通用的,因为它使用 codePoint 之类的属性 CupertinoIcon

虽然此代码会呈现其他 painter 命令,但不幸的是,该代码会在 Google Chrome 中呈现图标的占位符:

如何使图标出现?

【问题讨论】:

    标签: flutter flutter-layout flutter-web


    【解决方案1】:

    只要将package 参数添加到TextStyle,就会出现图标:

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

    documentation 这么说:

    To use a font family defined in a package, the package argument must be provided.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      相关资源
      最近更新 更多