flutter - 展开数据表以填充Flutter中的高度

标签 flutter dart datatable fill

我有 flutter 的问题。
我需要在屏幕上方填充一个DataTable。

我试图将数据表添加到Flex小部件中,但没有得到更改。

当我设置容器的高度时,就是这样,让我在屏幕的按钮处留出空白

谢谢!我为我的英语不好对不起

这是我的代码:

products.addAll(Product.getExampleList());

var table =

Container(
  child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child:SizedBox(
            child:
            Column(
              children: <Widget>[
                DataTable(
                    columns: <DataColumn>[
                      DataColumn(
                          label: Text("Código")
                      ),
                      DataColumn(
                        label: Text("Precio"),
                        numeric: true,
                      ),
                      DataColumn(
                          label: Text("Grupo")
                      ),
                      DataColumn(
                          label: Text("Descripción")
                      ),
                    ],
                    rows:
                    products.map<DataRow>((Product element) {
                      return DataRow(
                        key: Key(element.idProduct.toString()),
                        cells: <DataCell>[
                          DataCell(Text(element.code)),
                          DataCell(Text("\$ " + element.price.toStringAsFixed(2))),
                          DataCell(Text(element.group)),
                          DataCell(Text(element.description))
                        ],
                      );
                    }).toList()
                ),
              ],
            )
        ),
      ),
);


return  Container(
    color: Colors.white24,
    child:
      Column(
      children: <Widget>[
        Container(
          padding: EdgeInsets.all(10),
          child: Row(

            children: <Widget>[

              Text("Código: "),
              Flexible(
                child: TextField(
                  controller: tController,
                  decoration: InputDecoration(
                      hintText: "Ingrese Código"
                  ) ,
                ),
              ),
              RaisedButton(
                onPressed: onPressedSearch,
                child: Text("Buscar"),
              )
            ],
          ),
        ),
        Flex(
          direction: Axis.vertical,
          children: <Widget>[
            table
          ],
        ),
      ],
    )
);

最佳答案

您可以设置DataTable的dataRowHeight和headingRowHeight属性,使其高度等于屏幕高度。

your_number_of_rows = 4;
rowHeight = (MediaQuery.of(context).size.height - 56) / your_number_of_rows;

DataTable(dataRowHeight: rowHeight, headingRowHeight: 56.0, columns: ...)

关于flutter - 展开数据表以填充Flutter中的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59921422/

相关文章:

laravel - Yajra DataTable Laravel 中的 Foreach

http - 如何在flutter http put方法中通过body传递参数

flutter - 水平 ListView 不在网络上滚动,而是在移动设备上滚动

dart - 如何将 Assets 图像转换为文件?

dart - dart 中的 ByteBuffer.wrap 相当于什么?

javascript - 过滤列的集合

flutter - ScanStreamTransformer 上的 NULL 累加器

flutter - 如何在 flutter 中的文本字段中填充数据

dart - 将 BLoC 的接收器与另一个 BLoC 连接

javascript - DataTable,使用 mRender 时面临选择过滤器的问题