flutter 添加图标的实现

2023-07-23  本文已影响0人  别看后面有人

阿里图标地址:https://www.iconfont.cn/
选择好图标之后------》选择下载代码
然后复制进项目中

image.png
具体的使用
第一步:先新建图标代码:代码中的 0xe607来源于上图中的json中
image.png
class MyIcon{
  static const IconData category=IconData(
    0xe607,
    fontFamily: 'MyIcon',
    matchTextDirection: true
  );
  static const IconData redPagecaket=IconData(
      0xe608,
      fontFamily: 'MyIcon',
      matchTextDirection: true
  );
  static const IconData custom=IconData(
      0xe609,
      fontFamily: 'MyIcon',
      matchTextDirection: true
  );
}

第二步使用方法:

 children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            Icon(MyIcon.category,color: Colors.red,)
          ],

当然前提是先添加资源文件


image.png
上一篇 下一篇

猜你喜欢

热点阅读