有没有办法在 Flutter 上更改 ListTile 的前导背景?
Is there a way to change the leading's background of a ListTile on Flutter?
我正在使用 CircleAvatar 作为引导来制作列表。我想让背景和头像圆圈一样的颜色变成正方形。
The item 2 of the list shows what I mean
有简单的方法吗?
顺便说一句,这是我的代码:
child: new ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
child: Text(listData[i].index,
style: TextStyle(color: Colors.white),),
),
title: new Text(listData[i].word),
subtitle: new Text(listData[i].definition),
onTap: (){
print("Tocou!");
},
),
谢谢。
您可以删除 ListTile 的内容填充(水平 16)并使用 AspectRatio:
ListTile(
contentPadding: EdgeInsets.all(0),
leading: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.red,
child: Center(
child: Text("1",
style: TextStyle(color: Colors.white),),
),
),
),
title: Text(listData[i].word),
subtitle: Text(listData[i].definition),
onTap: (){
print("Tocou!");
},
),
我正在使用 CircleAvatar 作为引导来制作列表。我想让背景和头像圆圈一样的颜色变成正方形。
The item 2 of the list shows what I mean
有简单的方法吗?
顺便说一句,这是我的代码:
child: new ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
child: Text(listData[i].index,
style: TextStyle(color: Colors.white),),
),
title: new Text(listData[i].word),
subtitle: new Text(listData[i].definition),
onTap: (){
print("Tocou!");
},
),
谢谢。
您可以删除 ListTile 的内容填充(水平 16)并使用 AspectRatio:
ListTile(
contentPadding: EdgeInsets.all(0),
leading: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.red,
child: Center(
child: Text("1",
style: TextStyle(color: Colors.white),),
),
),
),
title: Text(listData[i].word),
subtitle: Text(listData[i].definition),
onTap: (){
print("Tocou!");
},
),