Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set align right in table with Flutter

I'm using flutter table. I would like to set numbers align right.(or center)

How can I make them locate?

I would like to header center. numbers to right.

enter image description here

             Container(
                margin: EdgeInsets.all(8.0),
                width: double.infinity,
                decoration: BoxDecoration(border: Border.all(width: 1.0)),
                child: Table(
                  columnWidths: {
                    0: FlexColumnWidth(1),
                    1: FlexColumnWidth(1),
                    2: FlexColumnWidth(4),
                    3: FlexColumnWidth(1),
                    4: FlexColumnWidth(1),
                    5: FlexColumnWidth(1),
                    6: FlexColumnWidth(1),
                  },
                  border: TableBorder.all(),
                  defaultVerticalAlignment: TableCellVerticalAlignment.middle,
                  children: <TableRow>[
                    TableRow(children: <Widget>[
                      Container(
                        padding: EdgeInsets.all(2.0),
                        child: Text('G',
                            style: TextStyle(fontWeight: FontWeight.bold)),
                      ),
                      Container(
                        padding: EdgeInsets.all(2.0),
                        child: Text('A',
                            style: TextStyle(fontWeight: FontWeight.bold)),
                      ),
                    ]
                  ),

        TableRow(children: <Widget>[
          Container(
            padding: EdgeInsets.all(2.0),
            child: Text('2'),
          ),
          Container(
            padding: EdgeInsets.all(2.0),
            child: Text('FW'),
          ),
          ]
        )

Too much code, then I wrote some of codes. Please take a look.

like image 721
tajihiro Avatar asked Nov 01 '25 21:11

tajihiro


2 Answers

Have alignment: Alignment.center inside Container,

Container(
         alignment: Alignment.center,
         padding: EdgeInsets.all(2.0),
         child: Text('G',
         style: TextStyle(fontWeight: FontWeight.bold)),
         ),
like image 195
Ravinder Kumar Avatar answered Nov 04 '25 12:11

Ravinder Kumar


This is an example and a part of your code ! Table children:

children: <TableRow>[
                  TableRow(
                    children: <Widget>[
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('G',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.center),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('A',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.center),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('P',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.center),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('P',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.center),
                    ),
                  ]),
                  TableRow(
                    children: <Widget>[
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('1',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('2',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('3',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('4',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                  ]),
                  TableRow(
                    children: <Widget>[
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('1',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('2',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('3',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                    Container(
                      padding: EdgeInsets.all(2.0),
                      child: Text('4',
                          style: TextStyle(fontWeight: FontWeight.bold),
                                 textAlign:TextAlign.end),
                    ),
                  ]),
                ])

pic

like image 41
Naveen Avidi Avatar answered Nov 04 '25 10:11

Naveen Avidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!