gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:15:54 29 4
gpt4 key购买 nike

我有一个黑色背景的 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com