在 flutter 中更改分页数据表的颜色?

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

我希望使用 flutter 改变分页数据表的颜色,

我使用深色主题和分页数据表采用那种颜色,我也从 flutter 网站上读到在这里输入链接描述

使用这个CardTheme,但是如何使用它.. 这是我的分页数据表的简单代码..

 class DataTableDemo extends StatelessWidget {
  Widget build(BuildContext context) {
    print("tesat");

    MySource mySource = new MySource(
      // ["test1##test2", "test3##test4", "test5##test6", "test7##test8"],
      //  ["test1##test2", "test3##test4", "test5##test6", "test7##test8"]
      test2,
      test3,
    );

    return Container(
      // appBar: AppBar(
      //   title: Text('Data Tables'),
      // ),
      //backgroundColor: Color(0xff232d37),
      color: Color(0xff232d37),
      child: ListView(
        padding: const EdgeInsets.all(2),
        children: [
          PaginatedDataTable(
            //header: Text('Header Text'),
            rowsPerPage: 10,
            columns: [
              DataColumn(label: Text('Header A')),
              DataColumn(label: Text('Header B')),
              DataColumn(label: Text('Header C')),
            ],
            //source: _DataSource(context),
            source: mySource,
          ),
        ],
      ),
    );
  }
}


class MySource extends DataTableSource {
  List<String> value;
  List<String> test1;
  String a;
  String b;
  MySource(this.value, this.test1) {
    print(value);
  }

  @override
  DataRow getRow(int index) {
    // TODO: implement getRow
    // print('test');
    //test1 = value[index].split("");
    return DataRow.byIndex(
      //color: MaterialStateColor.resolveWith((states) => Colors.blue),
      index: index,
      cells: [
        DataCell(Text(value[index].toString())),
        DataCell(Text(test1[index].toString())),
        DataCell(
          InkWell(
            onTap: () {
              print((value[index]));
            },
            child: Text("Click"),
          ),
        ),
      ],
    );
  }

  @override
  // TODO: implement isRowCountApproximate
  bool get isRowCountApproximate => false;

  @override
  // TODO: implement rowCount
  int get rowCount => value.length;

  @override
  // TODO: implement selectedRowCount
  int get selectedRowCount => 0;
}

但现在我得到了这个

我需要将颜色设置为

color: Color(0xff232d37),
任何帮助都适用 >>

问候

flutter dart datatable flutter-layout flutter-web
2个回答
5
投票

找到了,

Theme(
        data: Theme.of(context)
            .copyWith(cardColor: Color(0xff232d37), dividerColor: Colors.green),
        child: ListView(

这解决了我的问题

问候


0
投票

您还可以在

PaginatedDataTable
中更改
ThemeData
颜色:

ThemeData(
  cardTheme: CardTheme(
    surfaceTintColor: Colors.transparent,
  ),
);
© www.soinside.com 2019 - 2024. All rights reserved.