Expand DataTable to fill height in Flutter
7,389
You can set the dataRowHeight
and headingRowHeight
properties of the DataTable
to make its height equal to screen height.
your_number_of_rows = 4;
rowHeight = (MediaQuery.of(context).size.height - 56) / your_number_of_rows;
DataTable(dataRowHeight: rowHeight, headingRowHeight: 56.0, columns: ...)
Author by
Sebastian Alberto Bordi
Updated on December 17, 2022Comments
-
Sebastian Alberto Bordi over 1 year
I have a problem with flutter. I need to fill a DataTable in the height of screen.
I tried to add the dataTable inside a Flex widget, but I don't get changes.
When I set the heigh of the Container, that's work let me a white space at the button of the screen
Thank you! and i'm sorry for mi poor english
This my code:
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 ], ), ], ) );
-
DomingoMG about 4 yearsHave you used Wrap content?
-