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

时间:2017-09-01 21:40:11

标签: flutter

我在pubspec.yaml(icomoon.ttf)中声明了一个自定义图标字体。

Flutter的文档说要调用一个图标,请使用......

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.

),

我应该如何使用“myColor”色调调用大小为25px的“icomoon.ttf”字形“e901”的示例?

2 个答案:

答案 0 :(得分:2)

您需要在<?php $name = isset($_SESSION['key_whatever']) ? $_SESSION['key_whatever'] :null; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="s2q2.php" method="POST"> <p>Enter your name:</p> <input type="text" name="name" value="<?=$name?>"> <br> <button type="submit" name="s2q1"><span>Next </span></button> </form> </body> </html> /* on submit if youre not using any rewrite rules -> s2q2.php will be compiled and executed -------s2q2.php------- */ <?php session_start(); <--- need to be set $_SESSION['key_whatever'] = isset($_POST['name']) ? $_POST['name'] : null; ?> 窗口小部件中使用IconData来显示它,例如:

Icon

所以在你的情况下它会是这样的:

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

答案 1 :(得分:2)

我最终将谷歌图标定义表复制成一个主题&#34;我的应用程序的文件(&#34; lib / themes / my_icons.dart&#34;)因此,在此工作表中,图标的定义如下:

class MyIcons {
  MyIcons._();

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

}

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

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

还有一种方法可以创建颜色主题文件,例如&#34; lib / theme / my_colors.dart&#34;。在这个文件中的颜色&#34; myBlue&#34;被定义为。那么这个文件也可以包含在任何可以调用自定义调色板的面板的顶部,并且可以像这样调用图标:

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

希望这有助于其他人。