颤振 - 调用自定义图标字形的正确方法是什么?

问题描述:

我已经在pubspec.yaml(icomoon.ttf)中声明了自定义图标字体。颤振 - 调用自定义图标字形的正确方法是什么?

扑动的文件说,要调用一个图标,使用...

const IconData(
    this.codePoint, { 
    this.fontFamily, 
}); 

我有填充的元素应该包含的图标。

new Padding(
    padding: new EdgeInsets.only(top: 2.0), 

    how to invoke the glyph here? Need to be able to specify font size and 
    color too. 

), 

什么是我应该如何援引“icomoon.ttf”字形“E901”在大小25像素与色彩“myColor”的例子吗?

您需要使用IconDataIcon小工具来显示它,像:

new Icon(const IconData(0x41, fontFamily: 'Roboto'), size: 48.0, color: Colors.red); 

所以你的情况会是这样的:

new Icon(const IconData(0xe901, fontFamily: 'icomoon'), size: 25.0, color: myColor); 

我结束了复制谷歌图标定义表放到我的应用程序的“主题”文件中(“lib/themes/my_icons.dart”)因此,在此表中,图标定义如下:

class MyIcons { 
    MyIcons._(); 

    static const IconData superCheckMark = const IconData(0xe900, fontFamily: 'icomoon'); 

} 

在我想使用该图标的组件的顶部,我包含了该文件。然后图标被调用,像这样:

new Icon(MyIcons.superCheckMark, size: 30.0, color: Colors.white,), 

还有创建颜色主题文件,例如“LIB /主题/ my_colors.dart”的方式。在这个文件中定义了颜色“myBlue”。所以,那么这个文件还可以包含在其中自定义调色板将被调用任何面板的顶部,并调用它像这样的图标:

new Icon(MyIcons.superCheckMark, size: 16.0, color: MyColors.colors.myBlue,), 

希望这可以帮助其他人。