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

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

问题描述

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

如果有人知道,请帮助!谢谢

解决方案

使用

  import'package:flutter/material.dart';void main()=>runApp(MyApp());MyApp类扩展了StatelessWidget {@override窗口小部件build(BuildContext context){返回MaterialApp(主页:MyHomePage(),);}}类MyHomePage扩展了StatefulWidget {@override状态< StatefulWidget>createState(){返回_MyHomePageState();}}类_MyHomePageState扩展State< MyHomePage>{@override窗口小部件build(BuildContext context){返回脚手架(身体:中心(子代:主题(数据:Theme.of(context).copyWith(分隔线颜色:Colors.green),子级:DataTable(列: [DataColumn(label:Text('Language')),DataColumn(标签:Text('Year'))],行:[数据行(细胞: [DataCell(Text('Go')),DataCell(文本('2009'))],),数据行(细胞: [DataCell(Text('Dart')),DataCell(文本('2018'))],),数据行(细胞: [DataCell(Text('Java')),DataCell(文本('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天全站免登陆