如何使 Flutter TableRow 中的内容高度相同?

问题描述 投票:0回答:1

我创建了一个有 3 列的 flutter 表。第二列由一行两个容器组成,我想让容器与该行具有相同的高度。

import 'package:flutter/material.dart';

void main() => runApp(const TableExampleApp());

class TableExampleApp extends StatelessWidget {
  const TableExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Table Sample')),
        body: const TableExample(),
      ),
    );
  }
}

class TableExample extends StatelessWidget {
  const TableExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Table(
      border: TableBorder.all(),
      columnWidths: const <int, TableColumnWidth>{
        0: IntrinsicColumnWidth(),
        1: IntrinsicColumnWidth(),
        2: FixedColumnWidth(64),
      },
      defaultVerticalAlignment: TableCellVerticalAlignment.middle,
      children: [
        TableRow(
          children: [
            Container(
              padding: EdgeInsets.all(8.0),
              child: Text("Data 1"),
            ),
             TableCell(
              verticalAlignment: TableCellVerticalAlignment.fill,
              child: Row(
                children: [
                  Flexible(
                    child: Container(
                      color: Colors.red,
                      padding: EdgeInsets.all(8.0),
                      child: Text("Data 2"),
                    ),
                  ),
                  Container(
                    color: Colors.green,
                    padding: EdgeInsets.all(8.0),
                    child: Text("Data 3"),
                  ),
                ],
              ),
            ),
            Container(
              height: 64,
              color: Colors.blue,
            ),
          ],
        ),
      ],
    );
  }
}

我尝试用可扩展和灵活的小部件包装容器,但仍然没有结果

得到: enter image description here

预计: enter image description here

flutter flutter-dependencies
1个回答
0
投票

结果:

就像所有

Rows
一样,如果您希望它们展开,您需要将
crossAxisAlignment
:设置为
.stretch

TableCell(
              verticalAlignment: TableCellVerticalAlignment.fill,
              child: Row(
                // Add the below line to stretch the children
                crossAxisAlignment: CrossAxisAlignment.stretch, 
                children: [
                  Flexible(
© www.soinside.com 2019 - 2024. All rights reserved.