4

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,
        ),
      ])
    ],
);

5 Answers 5

9

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')
                            ]),
                   )
Sign up to request clarification or add additional context in comments.

Comments

5

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:

EdgeInsets Class:

3 Comments

sorry not working it gives this "The element type 'Padding' can't be assigned to the list type 'TableRow'."
@YoussefHad could you try to add the padding around the text, see my edit. I'm not at my home computer so cannot check if it work.
This adds padding around the content IN a row, and not space BETWEEN rows. Thus if your cell has a background colour, this approach won't work.
1

The easiest thing you can do is to wrap the content of each table cell with a Padding like so:

    TableRow   (children: [
              TableCell(
                child:Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(EMAIL,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,


                  ),),
                ),
              ),
              TableCell(
                  child:Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(authUser.email),
                  )
              ),
            ])

Comments

1

I just wrapped one of the elements with a SizedBox and set the defaultVerticalAlignment of the Table to middle:

Table(
  defaultVerticalAlignment: TableCellVerticalAlignment.middle,
  TableRow(
    children: [
      TableCell(
        SizedBox(
          height: 50,
          child: Text('Hello world'),
         ),
       ),
    ]   
  )
)

Comments

0

In addition to the answer of Ross:

Create a pad function for convenience, thus the padding can be adjusted for all cells at once:

Widget pad(Widget w) {
    return Padding(padding: EdgeInsets.symmetric(vertical: 8), child: w);
  }

Then use like this:

Table(
  columnWidths: {0: FractionColumnWidth(.4)},
  children:[
    TableRow(children: [
     pad(Text(
        'Original Title',
      )),
     pad(Text(
        original_title,
      )),
    ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.