flutter - Flutter Datatable Row、Column 和 Cell 的边框如何自定义?

标签 flutter datatable

我有一个黑色背景的 Flutter 应用程序,在添加 Datatable 小部件时,边框和文本不可见。
我为所有标签添加了 TextStyle 颜色,但如何为边框添加颜色?

DataTable(columns: [
    DataColumn(label: Center(child: Text('DATE', style: TextStyle(color: Colors.grey)))),
    DataColumn(label: Center(child: Text('FANS', style: TextStyle(color: Colors.grey)))),
    DataColumn(
        label: Text('LIKES', style: TextStyle(color: Colors.grey))),
    DataColumn(
        label:
            Text('EST. EARNINGS', style: TextStyle(color: Colors.grey))),
  ],

      rows: [
        DataRow(cells: [
          DataCell(Text('1')),
          DataCell(Text('2')),
          DataCell(Text('3')),
          DataCell(Text('4')),
        ])
      ]),

最佳答案

您可以使用 Theme小部件并覆盖 dividerColor .
这是示例代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(_title),
          backgroundColor: Colors.grey,
        ),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(
        child: Theme(
          data: Theme.of(context).copyWith(dividerColor: Colors.grey),
          child: DataTable(columns: [
            DataColumn(
              label: Container(
                width: 35,
                child: Center(
                  child: Text(
                    'DATE',
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
              ),
            ),
            DataColumn(
              label: Container(
                width: 35,
                child: Center(
                  child: Text(
                    'FANS',
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
              ),
            ),
            DataColumn(
              label: Container(
                width: 40,
                child: Center(
                  child: Text(
                    'LIKES',
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
              ),
            ),
            DataColumn(
              label: Container(
                width: 100,
                child: Center(
                  child: Text(
                    'EST. EARNINGS',
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
              ),
            ),
          ], rows: [
            DataRow(cells: [
              DataCell(
                Text(
                  '1',
                  style: TextStyle(color: Colors.grey),
                ),
              ),
              DataCell(
                Text(
                  '2',
                  style: TextStyle(color: Colors.grey),
                ),
              ),
              DataCell(
                Text(
                  '3',
                  style: TextStyle(color: Colors.grey),
                ),
              ),
              DataCell(
                Text(
                  '4',
                  style: TextStyle(color: Colors.grey),
                ),
              ),
            ])
          ]),
        ),
      ),
    );
  }
}
这是实际输出:
enter image description here

关于flutter - Flutter Datatable Row、Column 和 Cell 的边框如何自定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60575268/

相关文章:

flutter - 检查此函数结果的简写是什么?

c# - 如何让 ReportViewer 显示多页(例如每个 DataRow 显示一页)?

c# - 为什么我的数据表行中的值没有更新?

jsf-2 - p :fileDownload in p:dataTable does not work (just refreshes page) after performing search on the p:dataTable

flutter 错误: A value of type 'OutletListModel' can't be assigned to a variable of type 'List<OutletListModel>?'

email - Flutter - 如何实现一个电子邮件 TextFormField 小部件在多个屏幕中使用?

flutter - 如何在 flutter 中更改应用程序图标的形状?

flutter - 在 Flutter 中使屏幕的一部分可滚动

java - 如何在数据表中绑定(bind)两个类

laravel - Laravel 5 数据表中不区分大小写的常用过滤器