拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 在Flutter中创建表格的最佳方法

在Flutter中创建表格的最佳方法

白鹭 - 2022-03-09 1990 0 0

在这里,我使用容器创建表,并基于使用 flex 编号扩展以使标题和行相关。我认为这不是最好的方法,但我不知道如何创建这样的表格,任何人都可以给我一个建议吗?

这是代码:

_tableSection

Widget _bookingListSection(OnlineBookingListController controller) {
    return Column(
      children: [
        _buildHeaderTable(),
        Expanded(
          child: ListView.builder(
            padding: EdgeInsets.zero,
            itemCount: controller.listBooking.length,
            itemBuilder: (context, index) {
              int lastIndex = controller.listBooking.length - 1;

              return _buildContentTable(
                index,
                lastIndex,
                context,
                controller,
              );
            },
          ),
        ),
      ],
    );
  }

_buildHeaderTable(),

Widget _buildHeaderTable() {
    return Container(
      width: double.maxFinite,
      height: AppSize.DIMEN_64.h,
      padding: EdgeInsets.fromLTRB(
        AppSize.DIMEN_22.h,
        AppSize.DIMEN_16.h,
        AppSize.DIMEN_22.h,
        AppSize.DIMEN_16.h,
      ),
      decoration: BoxDecoration(
        color: AppColors.GREY_BLACK_BACKGROUND,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(AppSize.RADIUS_8.h),
          topRight: Radius.circular(AppSize.RADIUS_8.h),
        ),
      ),
      child: Row(children: [
        _titleHeaderTable('Time', 3),
        _titleHeaderTable('Phone Number', 3),
        _titleHeaderTable('Customer Name', 3),
        _titleHeaderTable('Room', 3),
        _titleHeaderTable('Waitress', 3),
        _titleHeaderTable('Status', 2),
        _titleHeaderTable('Action', 4),
      ]),
    );
  }

Widget _titleHeaderTable(String title, int flexNum) {
    return Expanded(
      flex: flexNum,
      child: Container(
        child: Text(
          title,
          textAlign: TextAlign.left,
          maxLines: 2,
          style: textStyleW700S14.copyWith(
            color: AppColors.WHITE,
          ),
        ),
      ),
    );
  }

然后对于我在行内使用 flex 的内容。你对这个有什么建议吗?

uj5u.com热心网友回复:

Table您可以使用和在 Flutter 中创建表格Data Table

  1. 使用表类:

在 Flutter 中创建表格的最佳方法

  1. 使用DataTable类:

在 Flutter 中创建表格的最佳方法

你也可以参考这个Table

uj5u.com热心网友回复:

Flutter 为此提供了一个 Table 类(但您也可以使用简单的 Row Column 组合来实作)。

这是 Table 档案的链接:Flutter Table

Container(
        color: Colors.white,
        padding: EdgeInsets.all(20.0),
        child: Table(
          border: TableBorder.all(color: Colors.black),
          children: [
            TableRow(children: [
              Text('Cell 1'),
              Text('Cell 2'),
              Text('Cell 3'),
            ]),
            TableRow(children: [
              Text('Cell 4'),
              Text('Cell 5'),
              Text('Cell 6'),
            ])
          ],
        ),
      )
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *