Created
February 16, 2020 06:56
-
-
Save ryanlid/fff09c7e862e4a50574e7fafd0ef8515 to your computer and use it in GitHub Desktop.
table 表格布局
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
title: "table 表格布局示例", | |
home: MyApp(), | |
), | |
); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("table 表格布局"), | |
), | |
body: Table( | |
// 设置表格的列数及列宽 | |
columnWidths: <int, TableColumnWidth>{ | |
0: FixedColumnWidth(100.0), | |
1: FixedColumnWidth(40.0), | |
2: FixedColumnWidth(80.0), | |
3: FixedColumnWidth(100.0), | |
}, | |
// 设置表格边框样式 | |
border: TableBorder.all( | |
color: Colors.black38, | |
width: 2.0, | |
style: BorderStyle.solid, | |
), | |
// 添加表格数据 | |
children: <TableRow>[ | |
// 第一行数据 | |
TableRow(children: [ | |
Text("姓名"), | |
Text("年龄"), | |
Text("性别"), | |
Text("身高"), | |
]), | |
// 第二行数据 | |
TableRow(children: [ | |
Text("张三"), | |
Text("18"), | |
Text("男"), | |
Text("170"), | |
]), | |
// 第三行数据 | |
TableRow(children: [ | |
Text("李四"), | |
Text("24"), | |
Text("男"), | |
Text("175"), | |
]), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment