Flutter 删除颤振中文本小部件的多余填充
文本小部件包装在一行中,带有一个扩展的大小框,高度设置为从下部小部件提供空间Flutter 删除颤振中文本小部件的多余填充,flutter,dart,Flutter,Dart,文本小部件包装在一行中,带有一个扩展的大小框,高度设置为从下部小部件提供空间 Row(children: <Widget>[ Expanded( child: Icon( Icons.favorite, color: Colors.grey, size: 24.0, )), Expanded( child: Text( "Dashboa
Row(children: <Widget>[
Expanded(
child: Icon(
Icons.favorite,
color: Colors.grey,
size: 24.0,
)),
Expanded(
child: Text(
"Dashboard",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
Expanded(
child: SizedBox(height: 10),
)
]),
行(子项:[
扩大(
子:图标(
我的最爱,
颜色:颜色。灰色,
尺寸:24.0,
)),
扩大(
子:文本(
“仪表板”,
样式:TextStyle(颜色:Colors.white,字体大小:20),
),
),
扩大(
子项:尺寸框(高度:10),
)
]),
类Foo扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回填充(
填充:仅限常量边集(底部:8.0),
孩子:排(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
填充物(
填充:仅限常量边集(右:4.0),
子项:图标(Icons.favorite,颜色:Colors.grey,大小:24.0),
),
正文(
“仪表板”,
样式:TextStyle(颜色:Colors.white,字体大小:20),
),
],
),
);
}
}
这会给你想要的结果
使用
行底部的填充
,从下面的小部件中获得所需的空间。如评论中所述,Expanded将占用所有可用空间。就像@Daniel所说的,Expanded将为您的小部件添加额外空间。以下是:
一种小部件,用于扩展行、列或Flex的子级,以便
子对象填充可用空间
使用扩展小部件生成行、列或Flex的子项
展开以沿主轴填充可用空间(例如。,
水平表示行或垂直表示列)。如果多个
孩子们被扩展,可用的空间被分配给他们
根据弹性系数
因此,您需要删除图标的展开部分
此处,已从图标中删除展开的示例添加了填充(忽略颜色):
更新代码如下:
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(children: [
Icon(
Icons.favorite,
color: Colors.grey,
size: 24.0,
),
SizedBox(width: 5), // Give some space to icon.
Expanded(
child: Text(
"Dashboard",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
Expanded(
child: SizedBox(height: 10),
)
]),
),
您可以使用SizedBox(宽度:5)
从图标中添加额外的空间。您可以详细说明您的问题吗?您想实现什么布局?文本没有填充,您是在谈论图标和文本之间的边距吗?如果是这样,那么您可能不应该使用Expanded
Expanded
拉伸并使用行的子行之间的额外空间。我试图在图标旁边放置文本,但两个图标之间的空间太大。如果我不能使用Expanded,那么如何将它们放在同一行中?
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(children: [
Icon(
Icons.favorite,
color: Colors.grey,
size: 24.0,
),
SizedBox(width: 5), // Give some space to icon.
Expanded(
child: Text(
"Dashboard",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
Expanded(
child: SizedBox(height: 10),
)
]),
),