簡體   English   中英

Flutter - Table / TableCell:如何設置一個單元格的背景顏色

[英]Flutter - Table / TableCell: How to set background color of one cell

我有一個表格小部件,我必須調整一個單元格的背景顏色。 所以我在TableCell小部件中放置了一個Container小部件並設置其顏色。 如果該行的所有單元格具有相同的高度 (b1),則此方法工作正常。 但是,如果另一個單元格的高度更大 (b2),我的方法就會失敗,正如您在此圖像中看到的那樣。

在此處輸入圖片說明

我知道Container的高度與其子項匹配,而不是其父項的高度。 但我想不出更好的方法。 有任何想法嗎?

這是我用於表的代碼:

Table(
    border: TableBorder.symmetric(
        inside: BorderSide(width: 1, color: AppColors.grey600),
        outside: BorderSide.none
    ),
    children: [
        TableRow(
            children: [
                TableCell(child: Container(child: Text('a'))),
                TableCell(child: Container(child: Text('b'))),
                TableCell(child: Container(child: Text('c'))),
            ],
        ),
        TableRow(
            children: [
                TableCell(child: Container(child: Text('abc abc abc'))),
                TableCell(child: Container(color: Colors.grey[300], child: Text('b'))),
                TableCell(child: Container(child: Text('c'))),
            ],
        ),
        TableRow(
            children: [
                TableCell(child: Container(child: Text('a'))),
                TableCell(child: Container(child: Text('b'))),
                TableCell(child: Container(child: Text('c'))),
            ],
        )
    ]
)

使用垂直對齊:TableCellVerticalAlignment.fill

TableCell(
  verticalAlignment: TableCellVerticalAlignment.fill, 
  child: Container(
    color: Colors.grey[300], 
    child: Text('b')
  )
),
TableRow(decoration: BoxDecoration( Colors.blue),

暫無
暫無

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

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