flutter图标按钮,如何在Flutter中调整图标/图标按钮的大小?

本文介绍如何在Flutter中调整IconButton的大小以及将图标更换为自定义图片。对于IconButton,可以通过设置Transform.scale来缩小图标;对于Icon,可以使用size属性更改图标大小。例如:Icon(Icons.radio_button_checked, size: 12,)。若想用Image.asset替换Icon,可直接在IconButton中使用Image.asset,如:IconButton(icon: Image.asset('images/IG.png'),)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I have 2 questions.

how to scale our icon ? I mean not a default icon from Flutter. but when you change into an Image. I have an Icon Button with an image like this:

Row(

mainAxisSize: MainAxisSize.max,

children: [

IconButton(

icon: new Image.asset("images/IG.png"),

),

IconButton(

icon: new Image.asset("images/Twitter.png"),

),

IconButton(

icon: new Image.asset("images/Fb.png"),

),

],

)

its only 3 icons. when I add more icon, its gonna break the layout into bricks yellow-black. how to make them become smaller ?

98893d192d4d9d865b95088f78595bae.png

Question above is for IconButton.

how to change an Icon with an Image ?

here are the code:

Icon(Icons.star, color: Colors.red)

how to change the 'star' with Image.asset ?

without any referal to other link, that only show the icon.

解决方案

You can use size property for Icon.

Icon(

Icons.radio_button_checked,

size: 12,

),

And for IconButton you can use

Transform.scale(

scale: 0.5,

child: IconButton(

onPressed: (){},

icon: new Image.asset("images/IG.png"),

),

),

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值