Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding some space between TableRows in Flutter

Tags:

flutter

dart

i'm creating a table in Flutter which contains some TableRows, i just want to add some space between these rows.

Table(
    columnWidths: {0: FractionColumnWidth(.4)},
    children:[
        TableRow(children: [
        Text(
          'Original Title',
        ),
        Text(
          original_title,
        ),
      ]),
      TableRow(children: [
        Text(
          'Original Language',
        ),
        Text(
          original_language,
        ),
      ])
    ],
);
like image 647
Youssef Had Avatar asked Sep 05 '25 16:09

Youssef Had


2 Answers

Here's how i did it.

Create a constant, lets say rowSpacer as

const rowSpacer=TableRow(
                  children: [
                      SizedBox(
                      height: 8,
                      ),
                      SizedBox(
                      height: 8,
                      )
                ]);

Remember the number of SizedBox widgets to add above should be same as the number of colums in your table. For this case I have 2 colums, hence 2 SizedBoxes.

Now use this constant to give spacing between rows.

              Table(
                  children: [
                       TableRow(
                          children: [
                            Text('Name:'),
                            Text('Aman kumar')
                            ]),
                       rowSpacer,                        //Using the Constant
                       TableRow(
                           children: [
                             Text('Date of Birth:'),
                             Text('September 27, 1998')
                            ]),
                   )
like image 193
Aman kumar Avatar answered Sep 08 '25 10:09

Aman kumar


Probably not the most efficient way but you can wrap the TableRow in a Padding Class

Padding(
  padding: EdgeInsets.all(8.0),
  child: const Card(child: Text('Hello World!')),
)

Something along the lines of:

Table(
  columnWidths: {0: FractionColumnWidth(.4)},
  children:[
    TableRow(children: [
      Padding(
      padding: EdgeInsets.symmetric(vertical: 8.0)
      child: Text(
        'Original Title',
      )),
      Padding(
      padding: EdgeInsets.symmetric(vertical: 8.0)
      child: Text(
        original_title,
      )),
    ]),
    TableRow(children: [
      Padding(
      padding: EdgeInsets.symmetric(vertical: 8.0)
      child: Text(
        'Original Language',
      )),
      Padding(
      padding: EdgeInsets.symmetric(vertical: 8.0)
      child: Text(
        original_language,
      )),
    ]),
  ],
);

Padding Class:

  • https://api.flutter.dev/flutter/widgets/Padding-class.html

EdgeInsets Class:

  • https://api.flutter.dev/flutter/painting/EdgeInsets-class.html
like image 44
Ross Avatar answered Sep 08 '25 10:09

Ross