[英]How to make a button in Flutter have the same shape as its icon?
您可以使用IconButton()
小部件而不是ElevtaedButton()
以及定义splashRadius
来更改飞溅效果的大小:
IconButton(
splashRadius: 1, // Set the Size of the splash area
color: Colors.grey,
icon: Icon(Icons.backspace),
onPressed: () {},
),
结果:
或者,如果您想使用ElevatedButton()
,请使用.icon
构造函数:
ElevatedButton.icon(
style: ElevatedButton.styleFrom(primary: Colors.grey.shade300),
label: Text('Hello World'),
icon: Icon(
Icons.backspace,
color: Colors.grey,
),
onPressed: () {},
)
结果:
类Icons
中有很多默认图标不适合您的应用。 您可以使用一些设计平台,例如 Figma,然后将其下载为svg
。 那么代码可能是:
InkWell(
onTap: () {},
child: SvgPicture.asset(path_to_svg_icon)
)
这样,您可以为您的图标编辑颜色、形状、样式...。 祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.