Post

flutter 展示自定义图标

参考:

展示图片: 需要在pubspec.yaml里进行配置

1
2
3
4
# 图片资源文件
  assets:
   - assets/images/abc.png
  - assets/images/xxx

在代码里使用

1
AssetImage('assets/images/abc.png')

Icon | ImageIcon| IconButton

使用sdk自带的Icon

1
Icon(Icons.home)

使用自定义的图片Icon

1
2
3
4
5
6
7
8
9
10
11
12
IconButton iconButton = IconButton(
            icon: Image.asset('assets/images/abc.png'),
            padding: EdgeInsets.all(3),
            iconSize: 25.0,
            onPressed: null,
          );

ImageIcon imageIcon = ImageIcon(
                AssetImage('assets/images/abc.png'),
                size: 25.0,
color: Colors.blue)
);
This post is licensed under CC BY 4.0 by the author.