簡體   English   中英

有沒有辦法在 Flutter 上更改 ListTile 的領先背景?

[英]Is there a way to change the leading's background of a ListTile on Flutter?

我正在使用 CircleAvatar 作為領導制作一個列表。 我希望背景與制作正方形的頭像圓圈顏色相同。

列表的第 2 項顯示了我的意思

有沒有簡單的方法來做到這一點?

順便說一下,這是我的代碼:

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!");
          },
        ),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM