在Flutter中,可以使用Table组件来创建表格,并在列名中添加任意文本。下面是一个简单的示例代码:
import 'package:flutter/material.dart';
class MyTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Table Example'),
),
body: Center(
child: Table(
border: TableBorder.all(),
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
children: [
TableRow(
decoration: BoxDecoration(
color: Colors.grey[200],
),
children: [
TableCell(
child: Text('Column 1'),
),
TableCell(
child: Text('Column 2'),
),
],
),
TableRow(
children: [
TableCell(
child: Text('Cell 1'),
),
TableCell(
child: Text('Cell 2'),
),
],
),
TableRow(
children: [
TableCell(
child: Text('Cell 3'),
),
TableCell(
child: Text('Cell 4'),
),
],
),
],
),
),
);
}
}
void main() {
runApp(MaterialApp(
home: MyTable(),
));
}
在这个示例中,我们使用Table组件创建了一个带有两列的表格。在第一行中,我们使用TableRow和TableCell组件创建了列名。在其余的行中,我们使用相同的组件来创建表格的单元格。
使用这个示例代码,你可以创建一个没有列名的表格,并自定义表格的样式和内容。
上一篇:表格没有链接。返回所有结果吗?