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
],
),
],
)
);
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: ...)
By setting the dataRowMaxHeight: double.infinity will help you..
DataTable(
sortAscending: true,
columnSpacing: 2.0,
dataRowMaxHeight: double.infinity, // Code to be changed.
dataRowMinHeight: 60, // Set the min required height.
dividerThickness: 1,
columns: <DataColumn>[
DataColumn(
label: Expanded(
child: Container(
width: 100,
child: Text(
'Account Type',
textAlign: TextAlign.center
),
),
))]),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With