我需要删除ListTile中领先的Widget和标题Widget之间的一些填充。它有太多的空格。有没有办法做到这一点?我为此使用的代码是这样的:
ListTile _getActionMenu(String text, IconData icon, Function() onTap) {
return new ListTile(
leading: new Icon(icon),
title: new Text(text),
onTap: onTap,
);
}
Run Code Online (Sandbox Code Playgroud)
小智 45
对于那些现在正在寻找干净的一行答案的人。您可以使用
ListTile(
horizontalTitleGap: desiredDoubleValue,
);
Run Code Online (Sandbox Code Playgroud)
Rus*_*mov 32
正如 Dinesh 在此处指出的那样,ListTile已收到一项minLeadingWidth财产。
默认值为40,因此要通过领导和标题之间减少空间x通minLeadingWidth: 40 - x。
Align 结果将取决于文本和平铺宽度。
使用Transform.translate了一致的结果。
ListTile(
leading: Icon(icon),
title: Transform.translate(
offset: Offset(-16, 0),
child: Text('Some text'),
),
);
Run Code Online (Sandbox Code Playgroud)
小智 24
您可以在ListTile上使用minLeadingWidth。默认值为 40,因此您可以使用较低的值使行距和标题更接近。
ListTile(
leading : Icon(Icons.settings),
title : Text("Settings"),
minLeadingWidth : 10,
);
Run Code Online (Sandbox Code Playgroud)
Jua*_*oza 15
我为此找到的一个丑陋的解决方法是在标题部分放置一个行小部件,然后将图标和文本放置在该行中,中间有一个 SizedBox。通过这种方式,您可以控制它们之间需要多少空间:
ListView(
shrinkWrap: true,
children: <Widget>[
ListTile(
title: Row(
children: <Widget>[
Icon(Icons.android),
SizedBox(
width: 5, // here put the desired space between the icon and the text
),
Text("Title") // here we could use a column widget if we want to add a subtitle
],
),
)
],
)
Run Code Online (Sandbox Code Playgroud)
wes*_*tdb 10
您可以使用Align并指定Alignment。
ListTile _getActionMenu(String text, IconData icon, Function() onTap) {
return new ListTile(
leading: new Icon(icon),
title: Align(
child: new Text(text),
alignment: Alignment(-1.2, 0),
),
onTap: onTap,
);
}
Run Code Online (Sandbox Code Playgroud)
小智 8
将水平标题间隙设置为 0
ListTile(
contentPadding: EdgeInsets.zero,
minLeadingWidth: 5,
***horizontalTitleGap: 0,***
leading: widget,
title: widget ,
)
Run Code Online (Sandbox Code Playgroud)
我这几天也有同样的问题,最后我发布了一个可以解决这个问题的包。
该包可在https://pub.dev/packages/list_tile_more_customizable 获得,使用该包我们可以设置水平标题间隙,当它设置为 0.0(零)时,前导和标题之间的填充将变为零。
用法:
ListTileMoreCustomizable(
title: Text("Title"),
trailing: Icon(Icons.people),
horizontalTitleGap: 0.0,
onTap: (details){},
onLongPress: (details){},
);
Run Code Online (Sandbox Code Playgroud)
编辑:
这种方法对我来说很好用,而且代码可以在https://github.com/Playhi/list_tile_more_customizable(原始代码太长)下获得 BSD 许可,我很难理解为什么一个用户会失败 -投票的答案没有提交任何问题。
小智 6
使用水平TileGap:
ListTile(
horizontalTitleGap: 0,
leading: CircleAvatar(
radius: 50,
backgroundImage:
NetworkImage("https://picsum.photos/250?image=1"),
),
title: Text("Image 6"),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2816 次 |
| 最近记录: |