[英]Change the background of ListTile widget to be transparent so that it blends with the color of the background page
我必須創建一個切換開關,旁邊有一些文字。 我認為最好使用ListTile小部件來做到這一點,該小部件使用標題顯示切換開關旁邊的文本並導致在文本之前顯示開關。 問題是當頁面的背景改變時ListTile背景是白色的。
我可以將 listtile 小部件放在容器內並更改容器的顏色以更改 listtile 的顏色,但我不想這樣做,因為背景會動態變化,我不想每次都更改容器的顏色. 有什么辦法可以讓listtile透明,以便它自動獲取背景顏色?
在圖像中,背景是黃色的,但 listtile 是白色的,我希望它是黃色的。 它目前的樣子。 我擁有的代碼:
Scaffold(
backgroundColor: Colors.yellow,
child: ListTile(
leading: ToggleSwitch
title: Text("Account"),
),
)
我無法執行以下操作,因為我可以設置腳手架的背景,但無法手動設置容器的顏色:
Scaffold(
backgroundColor: Colors.yellow,
child: Container(
color : Colors.yellow
ListTile(
leading: ToggleSwitch
title: Text("Account"),
),
),
)
有沒有辦法可以實現這一點,或者我應該在不使用ListTile小部件的情況下實現嗎?
您必須從文檔中創建自定義 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 })
從文檔頁面有一個關於如何創建自定義 ListTile 的示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.