Flutter开发之——Table

一 概述

  • Table用于创建表格试图组件
  • 一个完整的表格包含:Table(表格),TableRow(一行),TableCell(单元格)组成

二 表格的三要素(Table/TableRow/TableCell)

2.1 Table

构造函数
Table({
    Key? key,
    this.children = const <TableRow>[],
    this.columnWidths,
    this.defaultColumnWidth = const FlexColumnWidth(1.0),
    this.textDirection,
    this.border,
    this.defaultVerticalAlignment = TableCellVerticalAlignment.top,
    this.textBaseline, // NO DEFAULT: we don't know what the text's baseline should be
  })
常见属性说明
属性说明取值
children表格构成子view<TableRow>[]
defaultColumnWidth默认宽度FixedColumnWidth
border边框TableBorder
border
属性说明取值
color边框颜色Color
width边框宽度double
style边框样式BorderStyle枚举

2.2 TableRow

构造函数
const TableRow({ this.key, this.decoration, this.children })

2.3 TableCell

构造函数
const TableCell({
    Key? key,
    this.verticalAlignment,
    required Widget child,
  })

三 示例

3.1 表格代码

Table(
      defaultColumnWidth: FixedColumnWidth(100),
      border: TableBorder(
              top: BorderSide(color: Colors.red),
              left: BorderSide(color: Colors.red),
              right: BorderSide(color: Colors.red),
              bottom: BorderSide(color: Colors.red),
              horizontalInside: BorderSide(color: Colors.red),
              verticalInside: BorderSide(color: Colors.red),
            ),
       children: [
              TableRow(
                  decoration: ShapeDecoration(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0)), color: Colors.blue),
                  children: [
                    TableCell(child: Text('姓名',textAlign:TextAlign.center ,)),
                    TableCell(child: Text('性别',textAlign:TextAlign.center)),
                    TableCell(child: Text('年龄',textAlign:TextAlign.center)),
                  ]),
              TableRow(children: [
                TableCell(child: Text('张三',textAlign:TextAlign.center)),
                TableCell(child: Text('男',textAlign:TextAlign.center)),
                TableCell(child: Text('20',textAlign:TextAlign.center)),
              ]),
              TableRow(children: [
                TableCell(child: Text('李四',textAlign:TextAlign.center)),
                TableCell(child: Text('女',textAlign:TextAlign.center)),
                TableCell(child: Text('18',textAlign:TextAlign.center)),
              ]),
            ],
          )

3.2 效果图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值