Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change DataTable's column width in Flutter?

Tags:

flutter

I have a DataTable in my Flutter app. The problem is that when data is filled, the width of the columns is set automatically, and it too large. How can I manually set the column width? I tried to change the width parameters in the "Widget build", but it change the width of the whole table, but not a desired column.

like image 737
Smith Avatar asked Nov 01 '19 11:11

Smith


Video Answer


3 Answers

@Smith, you mean you can't do this ? if you could share some code ...

Widget build(BuildContext context) {
    return Scaffold(
      body: DataTable(
        columns: [DataColumn(label: Text('label'))],
        rows: [
          DataRow(cells: [DataCell(
            Container(
              width: 200, //SET width
              child: Text('text')))
              ])
        ]
      ),
    );
like image 64
Reginaldo Costa Avatar answered Oct 09 '22 19:10

Reginaldo Costa


Add columnSpacing property to DataTable. By default it is set to 56.0.

 columnSpacing: 30.0
like image 21
vishalknishad Avatar answered Oct 09 '22 17:10

vishalknishad


use columnSpacing in the databale then set 1 this takes then length of column text

columnSpacing: 0, 
like image 6
Maxamed Nuur Avatar answered Oct 09 '22 18:10

Maxamed Nuur