如何在Flutter中更改DataColumn的背景颜色?

问题描述 投票:0回答:1

我有一个DataTable小部件,用于以表格格式显示一些数据。我找不到任何方法来更改DataColumn的背景颜色,它默认为白色。

我尝试将label包装在Container内,但这无济于事,因为容器采用了孩子的尺寸。

有没有更简单的方法来设置'DataColum'的背景色?

下面是一些可供参考的代码-

DataTable(
  dataRowHeight: 70,
  headingRowHeight: 60,
  rows: List.generate(4, (index) {
    return DataRow(
      cells: <DataCell>[
        DataCell(
          Text("Number",),
        ),
        DataCell(
          Text(
          "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
          ),
        ),
      ]
    );
  }),
  columns: [
    DataColumn(
      label: Text("Name"),
    ),
    DataColumn(
      label: Text("Description"),
    ),
  ],
)
flutter dart flutter-layout
1个回答
0
投票

[ContainerBoxDecoration->Column/ Row-> DataTable] >>

您也可以使用BoxDecorationgradient属性。

查看本教程:YouTube代码示例:GitHub

child: Container(
        width: MediaQuery.of(context).size.width - 40.0,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12.0),
          color: Color(0xff5a348b),
          gradient: LinearGradient(
              colors: [Color(0xffebac38), Color(0xffde4d2a)],
              begin: Alignment.centerRight,
              end: Alignment(-1.0, -2.0)), //Gradient
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Row(
                children: <Widget>[
                  DataTable(
                    columns: <DataColumn>[
                      DataColumn(
                        label: Text(
                          'Storage',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 16.0,
                          ),
                        ),
                      ),
                      DataColumn(
                        label: Text(
                          '1TB',
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                            fontSize: 16.0,
                          ),
                        ),
                      ),
                    ],
                    rows: <DataRow>[
                      DataRow(cells: <DataCell>[
                        DataCell(
                          Text(
                            'Smart synchronization',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 16.0,
                            ),
                          ),
                        ),
                        DataCell(
                          Icon(
                            Icons.add,
                            color: Colors.white54,
                          ),
                        ),
                      ]),
                      DataRow(cells: <DataCell>[
                        DataCell(
                          Text(
                            'Full text search',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 16.0,
                            ),
                          ),
                        ),
                        DataCell(
                          Icon(
                            Icons.edit,
                            color: Colors.white54,
                          ),
                        ),
                      ]),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
© www.soinside.com 2019 - 2024. All rights reserved.