Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在flatter中更改DataColumn的背景色?_Flutter_Dart_Flutter Layout - Fatal编程技术网

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

Flutter 如何在flatter中更改DataColumn的背景色?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我有一个DataTable小部件,用于以表格格式显示一些数据。我无法找到任何方法来更改数据列的背景色,它默认为白色 我尝试将标签包装在容器中,但这没有帮助,因为容器采用子容器的尺寸 有没有更简单的方法来设置“DataColum”的背景色 下面是一些代码供参考- DataTable( dataRowHeight: 70, headingRowHeight: 60, rows: List.generate(4, (index) { return DataRow( ce

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

我尝试将
标签
包装在
容器中
,但这没有帮助,因为容器采用子容器的尺寸

有没有更简单的方法来设置“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"),
    ),
  ],
)
DataTable(
数据行高度:70,
头向生长高度:60,
行:List.generate(4,(索引){
返回数据行(
单元格:[
数据单元(
文本(“数字”),
),
数据单元(
正文(
“Lorem ipsum dolor sit amet,奉献精英。”,
),
),
]
);
}),
栏目:[
数据列(
标签:文本(“名称”),
),
数据列(
标签:文本(“说明”),
),
],
)

集装箱
箱饰
->
/
->
数据表

您也可以使用
BoxDecoration
gradient
属性

检查本教程:
代码示例:

child:容器(
宽度:MediaQuery.of(context).size.width-40.0,
装饰:盒子装饰(
边界半径:边界半径。圆形(12.0),
颜色:颜色(0xff5a348b),
梯度:线性梯度(
颜色:[颜色(0xffebac38),颜色(0xffde4d2a)],
开始:Alignment.centerRight,
结束:对齐(-1.0,-2.0)),//渐变
),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
填充物(
填充:仅限常量边集(顶部:8.0),
孩子:排(
儿童:[
数据表(
栏目:[
数据列(
标签:文本(
“存储”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:16.0,
),
),
),
数据列(
标签:文本(
“1TB”,
样式:TextStyle(
fontWeight:fontWeight.bold,
颜色:颜色,白色,
字体大小:16.0,
),
),
),
],
行:[
数据行(单元格:[
数据单元(
正文(
“智能同步”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:16.0,
),
),
),
数据单元(
图标(
Icons.add,
颜色:颜色。白色54,
),
),
]),
数据行(单元格:[
数据单元(
正文(
“全文搜索”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:16.0,
),
),
),
数据单元(
图标(
图标。编辑,
颜色:颜色。白色54,
),
),
]),
],
),
],
),
),
],
),
),

对于仍在寻找答案的人,我发现可以通过使用
IntrinsicWidth
Stack
容器来实现。我根据Buggycoder的问题修改了高度,
60
。由于
DataTable
小部件的默认
dataRowHeight
为kMinInteractiveDimension,因此您可以相应地替换它

     IntrinsicWidth(
          child: Stack(
            children: [
              Container(
                height: 60, // default would be kMinInteractiveDimension
                color: Colors.blue,
              ),
              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"),
                  ),
                ],
              ),
            ],
          ),
        )
IntrinsicWidth(
子:堆栈(
儿童:[
容器(
高度:60,//默认值为kMinInteractiveDimension
颜色:颜色,蓝色,
),
数据表(
数据行高度:70,
头向生长高度:60,
行:List.generate(4,(索引){
返回数据行(单元格:[
数据单元(
正文(
“数字”,
),
),
数据单元(
正文(
“Lorem ipsum dolor sit amet,奉献精英。”,
),
),
]);
}),
栏目:[
数据列(
标签:文本(“名称”),
),
数据列(
标签:文本(“说明”),
),
],
),
],
),
)

如果您想突出显示您的列,可以简单地更改DataColumn中文本的颜色,而不是更改背景。

现在在Flatter 1.22版中,您可以这样做

DataTable(
    headingRowColor:
        MaterialStateColor.resolveWith((states) => Colors.blue),
    columns: [
       DataColumn(),
       DataColumn(),
                
    ],
           
    rows: [
      DataRow(
          cells: [
              DataCell(),
              DataCell(),
          ],
      ),
    ],
)
DataTable(
showCheckboxColumn:false,
数据行高:35,
头向生长高度:35,
列:[//列列表],
行:List.generate(//改用这个
DataTable(
    headingRowColor:
        MaterialStateColor.resolveWith((states) => Colors.blue),
    columns: [
       DataColumn(),
       DataColumn(),
                
    ],
           
    rows: [
      DataRow(
          cells: [
              DataCell(),
              DataCell(),
          ],
      ),
    ],
)
 DataTable(
          showCheckboxColumn: false,
          dataRowHeight: 35,
          headingRowHeight: 35,
          columns: <DataColumn>[//column list],
          rows: List.generate( // use this instead of map()
            yourlist.length, (index) {
            return DataRow(
              color: MaterialStateColor.resolveWith((states) {
                return index % 2 == 0 ? Colors.red : Colors.black; //make tha magic!
              }),
              cells: [//cells list],
            );
          },
         ),
        ),
[![enter image description here][1]][1]DataTable(
    headingRowColor:
    MaterialStateColor.resolveWith((states) => Colors.blue),
    dataRowColor: MaterialStateColor.resolveWith((states) => Colors.grey),
    columns: const <DataColumn>[
      DataColumn(
        label: Text(
          'Profesional',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Entregados',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Aceptado',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Rechazado',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Pendiente',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Total',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Precio Aceptado',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Precio Rechazado',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
      DataColumn(
        label: Text(
          'Precio Pendiente',
          style: TextStyle(fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),
        ),
      ),
    ],
    rows: const <DataRow>[
      DataRow(
        cells: <DataCell>[
          DataCell(Text('Iván Molina Pastor',style: TextStyle(color: Colors.blue),)),
          DataCell(Text('1',style:TextStyle(color: Colors.blueAccent),)),
          DataCell(Text('1',style: TextStyle(color: Colors.lightGreen),),),
          DataCell(Text('0',style: TextStyle(color: Colors.redAccent),)),
          DataCell(Text('0',style: TextStyle(color: Colors.orangeAccent),)),
          DataCell(Text('€ 36.30',style: TextStyle(color: Colors.indigo),)),
          DataCell(Text('€ 36.30',style: TextStyle(color: Colors.lightGreen),)),
          DataCell(Text('€ 0.00',style: TextStyle(color: Colors.red),)),
          DataCell(Text('€ 0.00',style: TextStyle(color: Colors.yellowAccent),)),
        ],
      ),
      DataRow(
        cells: <DataCell>[
          DataCell(Text('Juan Celdran Alenda',style:TextStyle(color: Colors.blue),)),
          DataCell(Text('3',style:TextStyle(color: Colors.blueAccent),)),
          DataCell(Text('2',style: TextStyle(color: Colors.lightGreen),),),
          DataCell(Text('0',style: TextStyle(color: Colors.redAccent),)),
          DataCell(Text('0',style: TextStyle(color: Colors.orangeAccent),)),
          DataCell(Text('€ 8,433.70',style: TextStyle(color: Colors.indigo),)),
          DataCell(Text('€ 6,316.20',style: TextStyle(color: Colors.lightGreen),)),
          DataCell(Text('€ 0.00',style: TextStyle(color: Colors.red),)),
          DataCell(Text('€ 2,117.50',style: TextStyle(color: Colors.yellowAccent),)),
        ],
      ),

    ],
  ),