简体   繁体   English

将 ListTile 小部件的背景更改为透明,使其与背景页面的颜色混合

[英]Change the background of ListTile widget to be transparent so that it blends with the color of the background page

I had to create a toggle switch with some text next to it.我必须创建一个切换开关,旁边有一些文字。 I thought it was better to do it by using the ListTile widget which uses title to display the text next to the toggle switch and leading to display the switch before the text.我认为最好使用ListTile小部件来做到这一点,该小部件使用标题显示切换开关旁边的文本并导致在文本之前显示开关。 The problem is that when the background of the page changes the ListTile background is white.问题是当页面的背景改变时ListTile背景是白色的。

I can put the listtile widget inside a container and change the color of the container to change the color of the listtile but I don't want to do that because the background changes dynamically and I don't want to change the color of container everytime.我可以将 listtile 小部件放在容器内并更改容器的颜色以更改 listtile 的颜色,但我不想这样做,因为背景会动态变化,我不想每次都更改容器的颜色. Is there any way I can make the listtile transparent so that it gets the color of the background automatically?有什么办法可以让listtile透明,以便它自动获取背景颜色?

As soon in the image, background is yellow but listtile is white and I want it to be yellow.在图像中,背景是黄色的,但 listtile 是白色的,我希望它是黄色的。 How it currently looks .它目前的样子 The code that I have:我拥有的代码:

Scaffold(
 backgroundColor: Colors.yellow,
        child: ListTile(
          leading:  ToggleSwitch
          title: Text("Account"),
        ),
      )

I cannot do the following because I can set the background of the scaffold but I cannot set the color of the container manually:无法执行以下操作,因为我可以设置脚手架的背景,但无法手动设置容器的颜色:

Scaffold(
 backgroundColor: Colors.yellow,
        child: Container(
color : Colors.yellow 
ListTile(
          leading:  ToggleSwitch
          title: Text("Account"),
        ),
      ),
)

Is there a way I can achieve this or should I implement without using the ListTile widget?有没有办法可以实现这一点,或者我应该在不使用ListTile小部件的情况下实现吗?

you have to create a custom listTile as from documentation ListTile constructors dont take a color您必须从文档中创建自定义 listTile ListTile 构造函数不带颜色

 ListTile({Key key, Widget leading, Widget title, Widget subtitle, Widget trailing, bool isThreeLine: false, bool dense, EdgeInsetsGeometry contentPadding, bool enabled: true, GestureTapCallback onTap, GestureLongPressCallback onLongPress, bool selected: false }) 

from the documentation page there is an eample on how to create a custom ListTile从文档页面有一个关于如何创建自定义 ListTile 的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM