【Flutter】【widget】Table 表格widget


在这里插入图片描述

前言

Table 表格widget,其实很少使用到的,等有需要的时候在查看该widget


一、Table 是什么?

表格widget,但是不能像excel 那么强大。

项目Value
电脑$1600
手机$12
导管$1

二、使用步骤

项目Value
Table一个表格
TableRow一行
TableCell一个单元格

1.Table 基础使用

代码如下(示例):

    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Table(
        children: [
          TableRow(children: [
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            )
          ]),
          TableRow(children: [
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            )
          ])
        ],
      ),

在这里插入图片描述

2.宽度

宽度的设置的几种形式

  • FlexColumnWidth
 //columnWidths 单元格的宽,map 哪列 :宽度
  columnWidths: {
    0: FlexColumnWidth(20),
    1: FlexColumnWidth(10),
    2: FlexColumnWidth(10),
    3: FlexColumnWidth(10)
  },

如图:
在这里插入图片描述

  • IntrinsicColumnWidth:以那个最宽的单元格为该列的宽度
   columnWidths: {
     0: IntrinsicColumnWidth(),
     1: FlexColumnWidth(10),
     2: FlexColumnWidth(20),
     3: FlexColumnWidth(10)
   },

如图:
在这里插入图片描述

  • MaxColumnWidth:以那个最宽的单元格为该列的宽度,设置最大值,如果超过这个最大也是取最大值
        columnWidths: const {
          0: MaxColumnWidth(FlexColumnWidth(20), FlexColumnWidth(200)),
          1: FlexColumnWidth(10),
          2: FlexColumnWidth(10),
          3: FlexColumnWidth(10)
        },

3.设置边框

代码如下(示例):

    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Table(
        border: TableBorder(
          //添加上行左右的网格线
            top: BorderSide(color: Colors.red),
            left: BorderSide(color: Colors.red),
            bottom: BorderSide(color: Colors.red),
            right: BorderSide(color: Colors.red),
            //水平线
            horizontalInside: BorderSide(color: Colors.red),
            //垂直方向
            verticalInside: BorderSide(color: Colors.red)),
        //columnWidths 单元格的宽,map 哪列 :宽度
        columnWidths: {
          0: FlexColumnWidth(20),
          1: FlexColumnWidth(10),
          2: FlexColumnWidth(10),
          3: FlexColumnWidth(10)
        },
        children: [
          TableRow(children: [
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            )
          ]),
          TableRow(children: [
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            ),
            TableCell(
              child: Text(' i am one '),
            )
          ])
        ],
      ),
// This trailing comma makes auto-formatting nicer for build methods.
    );

该处使用的url网络请求的数据。

4.TableCell设置单元格式widget等其他设置

  • 可以单元的内容设置为widget
  TableCell(
       child: Card(child: Text(' i am onedfasdfadsfasd ')),
     ),

在这里插入图片描述

  • 设置垂直方向的对齐方式:
    TableCell(
         verticalAlignment: TableCellVerticalAlignment.middle,
        child: Text(' i am onedfasdfadsfasd '),
      ),

在这里插入图片描述

  • 设置背景颜色
 TableRow(
              decoration: BoxDecoration(
                  color: Colors.green,
                  borderRadius: BorderRadius.all(Radius.circular(15))),
              children: [
                TableCell(
                  verticalAlignment: TableCellVerticalAlignment.bottom,
                  child: Text(' i am onedfasdfadsfasd '),
                ),

在这里插入图片描述


总结

欢迎关注,留言,咨询,交流!
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值