减少图标和文本之间的间距 - Flutter OutlinedButton
有没有一种简单的方法可以减少 OutlinedButton
上图标和文本之间的间距?
下面是我的代码。做了一些不同的尝试,但没有成功。
OutlinedButton.icon(
onPressed: () {},
icon: Icon(Icons.flash_on_outlined, size: 20.0),
label: Text(
'Surge',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
style: OutlinedButton.styleFrom(
padding: EdgeInsets.zero,
//fixedSize: Size(40, 25),
backgroundColor: Colors.blue[100],
side: BorderSide(
color: Colors.blue,
width: 1,
),
),
),
Is there an easy way to reduce the space between the icon and text on an OutlinedButton
?
Below is my code. Have made a few different attempts but no luck.
OutlinedButton.icon(
onPressed: () {},
icon: Icon(Icons.flash_on_outlined, size: 20.0),
label: Text(
'Surge',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
style: OutlinedButton.styleFrom(
padding: EdgeInsets.zero,
//fixedSize: Size(40, 25),
backgroundColor: Colors.blue[100],
side: BorderSide(
color: Colors.blue,
width: 1,
),
),
),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在使用
OutlinedButton.icon
。如果您查看其源代码,您会发现它根本没有什么神奇之处:它只是将图标和文本放在Row
中,并在中间放置一个SizedBox
作为间隙,其源代码如下:因此,如果您不喜欢这个默认的 8 单位间隙,则只需不要使用
.icon
构造函数即可。只需使用普通的构造函数并传入一个Row
作为它的子元素,可以有任何你想要的间隙:You are using
OutlinedButton.icon
. If you look into its source code, you'll see that it's nothing magical at all: it simply puts your icon and text in aRow
and places aSizedBox
in the middle as a gap, its source code is as follows:So, if you don't like this default 8-unit gap, simply don't use
.icon
constructor. Just use the normal constructor and pass in aRow
as its child, with whatever gap you want:我认为实现这种情况的最佳方法是将图标按钮替换为带有
RichText
作为子项的按钮:此解决方案删除了图标的任何边距。
The best way to implement such case I think is to replace icon button with button with
RichText
as a child:This solution removes any margin from an icon.
您的尺寸,关于图标和文本,是块还是可以修改它?
your size, about the icon and the text, are block or you can modify it?