美文网首页程序员
Flutter学习笔记07-Icon

Flutter学习笔记07-Icon

作者: zombie | 来源:发表于2020-09-25 15:57 被阅读0次

Fluttter中,可以像Web开发一样使用iconfont,iconfont即“字体图标”,它是将图标做成字体文件,然后通过指定不同的字符而显示不同的图片。Icon假定渲染的图标为正方形, 非正方形图标可能会错误显示。
在Flutter开发中,iconfont和图片相比有如下优势:
1.体积小:可以减小安装包大小。
2.矢量的:iconfont都是矢量图标,放大不会影响其清晰度。
3.可以应用文本样式:可以像文本一样改变字体图标的颜色、大小对齐等。
4.可以通过TextSpan和文本混用。
Flutter默认包含了一套Material Design的字体图标,在pubspec.yaml文件中的配置如下:

flutter:
  uses-material-design: true

代码示例:

class IconDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          Icon(Icons.favorite, color: Colors.pink, size: 24.0),
          Icon(Icons.audiotrack, color: Colors.green, size: 30.0),
          Icon(Icons.beach_access, color: Colors.blue, size: 36.0),
        ],
      ),
    );
  }
}
运行效果图如下:

代码传送门

相关文章

网友评论

    本文标题:Flutter学习笔记07-Icon

    本文链接:https://www.haomeiwen.com/subject/ffyfuktx.html