首页 > 建站教程 > APP开发,混合APP >  Flutter笔记27:Icon图标正文

Flutter笔记27:Icon图标

Flutter图标、图片图标ImageIcon和IconButton图标按钮详解。这里要提一下,ImageIcon非常强大,引入的png图片,无论什么颜色,通过设置color,都能在app呈现出设置的颜色:
class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Icon组件',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Icon组件'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              //普通图标
              Icon(
                Icons.favorite,
                size: 30.0,
                color: Colors.red,
              ),
              //图片图标
              ImageIcon(
                AssetImage('assets/images/digg.png'),
                //这里的颜色会智能修改png图片所呈现的颜色,不设置color,则png是什么颜色,图标就是什么颜色
                color: Colors.blue,
                size: 48.0,
              ),
              //图标按钮
              IconButton(icon: Icon(Icons.print), onPressed: () => print('点击')),
            ],
          ),
        ),
      ),
    );
  }
}