[英]How to set the padding between leading and title from Flutter ListTile?
我有一個折衷的解決方案,但不能滿足我。
final int padding=10; //the padding you wanna set.
ListTile(
leading: Icon(icon),
title: Container(
height: 30,
child: Stack(
alignment: Alignment.centerLeft,
overflow: Overflow.visible,
children: <Widget>[
Positioned(
child: title,
left: padding-35,
),
],
),
),
);
是的。 您可以使用負邊距。 這絕對有效。 但它並不完美。所以有人可以提供更好的解決方案嗎?
========== 附加 ============
我在下面看到一些答案。但你似乎沒有得到我的觀點。
Flutter ListTile 中的領先和標題之間的默認填充對我來說太大了。 我想自己調整填充。 僅用 Padding 小部件包裝標題無法達到目標。
========== 我找到了一個更好的解決方案 ============
final int padding = 10; //the padding you wanna set.
ListTile(
leading: Icon(icon),
title: Container(
transform: Matrix4.translationValues(padding - 35, 0.0, 0.0),
child: title,
),
);
使用 Padding 小部件,例如:
ListTile(
leading: Icon(Icons.location_on),
title: Padding(
// change left :
padding: const EdgeInsets.only(left: 30),
child: Text('hello world'),
),
),
您可以為此向標題小部件添加填充。
將您的代碼替換為:
final double padding=10; //the padding you wanna set.
ListTile(
leading: Icon(icon),
title: Padding(
padding: const EdgeInsets.all(padding),
child:Container(
height: 30,
child: Stack(
alignment: Alignment.centerLeft,
overflow: Overflow.visible,
children: <Widget>[
Positioned(
child: title,
left: padding-35,
),
],
),
),
),
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.