我在最近的应用程序中使用DataTable
,我需要更改行线的颜色或使其不可见(我是说我不想让我的表显示任何行线)
如果有人知道,请帮助!谢谢
答案 0 :(得分:2)
您可以使用Theme小部件并覆盖dividerColor
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'))
],
),
]
),
),
),
);
}
}
答案 1 :(得分:1)
如果你还在寻找答案,这里是代码
return DataRow.byIndex(
index: row.key,
color: MaterialStateColor.resolveWith(
(states) {
if (row.key % 2 == 0) {
return Colors.blue[50];
} else {
return Colors.white;
}
},
),