刚刚注意到,ListTile覆盖按钮动画时,包装在一个容器,背景颜色设置为任何东西,但不透明。用设置颜色的容器包装ListTile是我知道的改变ListTile背景色的唯一方法。有没有其他方法可以改变ListTile的背景色而不松开按钮动画?
Container(
color: Colors.green,
child: ListTile(
title: Text('Test'),
trailing: IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
),
)输出

发布于 2020-03-29 17:15:54
这是因为InkWell的工作方式(有些按钮,如IconButton,使用InkWell或InkResponse作为其父按钮)。您可以在这个github问题页面上更多地了解它。
为了使这种涟漪效应显示在装饰容器的顶部(代码中的绿色容器)上,它需要在小部件显示树中的容器上方设置一个 make 小部件。因此,您应该编辑代码并在容器中添加一个具有透明度的小部件,因此小部件显示树将看起来像容器->材料-> Ink。
Container(
color: Colors.green,
child: Material(
type: MaterialType.transparency,
child: ListTile(
title: Text('Test'),
trailing: IconButton(
icon: Icon(Icons.add),
onPressed: () {},
),
),
),
),https://stackoverflow.com/questions/60917682
复制相似问题