![](/img/trans.png)
[英]How to set the padding between leading and title from Flutter ListTile?
[英]How to shorten padding around leading in ListTile?
请参考我下面的代码和截图,左右两侧都有空格,带有前导图标。 我想这是在ListTile
或LayoutBuilder
中领先的默认布局,无论如何,我怎样才能缩短这些空间或Padding
?
return Container(
height: 100,
child: Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(0)),
),
child: ListTile(
horizontalTitleGap: 0,
minLeadingWidth : 10,
leading: assetId != null
? Container(
width: 150,
height: 150,
decoration: BoxDecoration(
border: Border.all(
color: const Color.fromARGB(255, 255, 255, 255)),
color: Color.fromARGB(255, 255, 255, 255),
shape: BoxShape.circle,
),
child: LayoutBuilder(
builder: (context, constraints) {
return Image.asset(
iconPass,
fit: BoxFit.none,
scale: 5,
);
},
),
)
: null,
title: Text(
name,
style: MyText(myFontSize: 15).style(),
),
subtitle: subTitle,
trailing: iconNavigator(
destinationTo: cards(),
context: context,
backForward: "forward",
myIcon: const Icon(Icons.more_vert),
),
),
),
);
您看到的padding
是因为 flutter 正在尝试在所有四个方向上扩展小部件,然后尝试fit
其放入leading
小部件内,为了克服这个问题,请尝试使用SizedBox
包装您的leading
并给它一个fixed width
。
leading: SizedBox(width: 60, child: <Your Widget here>),
SizedBox
之前:SizedBox
后:Center(
child: Column(
children: const [
Card(
child: ListTile(
leading: SizedBox(width: 60, child: FlutterLogo(size: 56.0)),
title: Text('Two-line ListTile'),
subtitle: Text('Here is a second line'),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
leading: SizedBox(width: 60, child: FlutterLogo(size: 72.0)),
title: Text('Three-line ListTile'),
subtitle: Text(
'A sufficiently long subtitle warrants three lines.'),
trailing: Icon(Icons.more_vert),
// isThreeLine: true,
),
),
Card(
child: ListTile(
leading: SizedBox(width: 60, child: FlutterLogo(size: 128.0)),
title: Text('Three-line ListTile'),
subtitle: Text(
'A sufficiently long subtitle warrants three lines.'),
trailing: Icon(Icons.more_vert),
),
),
],
)),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.