Icon(Icons.search,color: Colors.red,size: 40),
图 标 官 网 Flutter
Flutter中借助阿里巴巴图标库自定义字体图标
1. 导入字体图标文件;
fonts:
- family: myIcon #根据自己的需求定义
fonts:
- asset: fonts/iconfont.ttf
2、 为了使用方便,我们定义一个 MyIcons 类,功能和 Icons 类一样
class MyIcons{
// book 图标
static const IconData book = IconData(
0xe614,
fontFamily: 'myIcon',
matchTextDirection: true
);
// 微信图标
static const IconData wechat = IconData(
0xec7d,
fontFamily: 'myIcon',
matchTextDirection: true
);
}
3、 使用
Icon(MyIcons.book,color: Colors.purple),
4.使用图片代替图标
GestureDetector(
onTap: () { // 点击图标后执行的操作 print("点击了"); }, child: Image.asset( 'images/home/setting.png', width: height / 10, height: height / 10, ), ),
IconButton( //最好用上方的
onPressed: () {
// 点击图标后执行的操作(如果下方有文字间距太大)
print("点击了");
},
icon: Image.asset(
'images/home/page.png',
width: 10,
height: 10,
),
),
浙公网安备 33010602011771号