Flutter:有什么办法可以改变DataTable的行线颜色? [英] Flutter: Is there any way to change the row line color of DataTable?

查看:27
本文介绍了Flutter:有什么办法可以改变DataTable的行线颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在最近的应用程序中使用 DataTable,我需要更改行线的颜色或使其不可见(我的意思是我不想让我的表显示任何行线)

如果有人知道请帮忙!谢谢

解决方案

使用

import 'package:flutter/material.dart';无效的主要()=>运行应用程序(我的应用程序());MyApp 类扩展 StatelessWidget {@覆盖小部件构建(BuildContext 上下文){返回材料应用程序(主页:我的主页(),);}}类 MyHomePage 扩展 StatefulWidget {@覆盖状态<StatefulWidget>创建状态(){返回 _MyHomePageState();}}类 _MyHomePageState 扩展状态<MyHomePage>{@覆盖小部件构建(BuildContext 上下文){返回脚手架(身体:中心(孩子:主题(数据:Theme.of(context).copyWith(分隔线颜色:Colors.green),孩子:数据表(列: [数据列(标签:文本('语言')),数据列(标签:文本('年份'))],行:[数据行(细胞: [数据单元(文本('Go')),数据单元(文本('2009'))],),数据行(细胞: [数据单元(文本('飞镖')),数据单元(文本('2018'))],),数据行(细胞: [数据单元(文本('Java')),数据单元(文本('1992'))],),]),),),);}}

I'm using DataTable in my recent app and i need to change the color of the row line or make it invisible (i mean I don't want to my table shows any row line)

If anyone knows please help! thanks

解决方案

Use Theme widget and overriding the dividerColor as shown below.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

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

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Theme(
          data: Theme.of(context).copyWith(
              dividerColor: Colors.green
          ),
          child: DataTable(
              columns: [
                DataColumn(label: Text('Language')),
                DataColumn(label: Text('Year'))
              ],
              rows: [
                DataRow(
                  cells: [
                    DataCell(Text('Go')),
                    DataCell(Text('2009'))
                  ],
                ),
                DataRow(
                  cells: [
                    DataCell(Text('Dart')),
                    DataCell(Text('2018'))
                  ],
                ),
                DataRow(
                  cells: [
                    DataCell(Text('Java')),
                    DataCell(Text('1992'))
                  ],
                ),
              ]
          ),
        ),
      ),
    );
  }
}

这篇关于Flutter:有什么办法可以改变DataTable的行线颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆