Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Row Not Aligning to the Left

I'm having trouble aligning a row with text to the left of a column.

The layout looks like the following:

enter image description here

However, I would like the user's name ("Peter Jonathan") and the user's handle ("@pj"), to align to the left most side. Any advice on how I can do this?

Here is the current code I have:

class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        elevation: 0.0,
//        title: Text('Profile'),
      ),
      body: new Container(
        padding: EdgeInsets.fromLTRB(25.0, 0.0, 25.0, 10.0),
        child: new Column(
          children: <Widget>[
            new Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                new Container(
                  width: 100.0,
                  height: 100.0,
                  child: new Center(
                    child: new Text(
                      "PJ",
                      style: new TextStyle(fontSize: 40.0),
                    ),
                  ),
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    border: new Border.all(color: Colors.purple),
                  ),
                ),
                new Column(
                  children: <Widget>[
                    new Row(
                      children: <Widget>[
                        new Padding(
                          padding: EdgeInsets.all(10.0),
                          child: new Column(
                            children: <Widget>[
                              new Text(
                                '100',
                                style: new TextStyle(fontSize: 20.0),
                              ),
                              new Text('Followers'),
                            ],
                          ),
                        ),

                        new Padding(
                          padding: EdgeInsets.all(10.0),
                          child: new Column(
                            children: <Widget>[
                              new Text(
                                  '100',
                                style: new TextStyle(fontSize: 20.0),
                              ),
                              new Text('Following'),
                            ],
                          ),
                        ),
                      ],
                    ),
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        new Text("Peter Jonathan",
                          style: new TextStyle(
                            fontSize: 18.0,
                            fontWeight: FontWeight.bold,
                          ),
                          textAlign: TextAlign.left,
                        ),
                      ],
                    ),
                    new Row(
                      children: <Widget>[
                        new Text("@pj",
                          style: new TextStyle(
                            fontSize: 18.0,
                            fontStyle: FontStyle.italic,
                            color: Color.fromRGBO(155, 155, 155, 1.0),
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

I've heard that using a flexible is key, but when I do that it's not compiling correctly. Do I need to wrap the name and handle in containers?

like image 437
PJQuakJag Avatar asked Nov 06 '18 04:11

PJQuakJag


People also ask

How do you align two text in a row in Flutter?

You just have to add the Row property mainAxisAlignment: MainAxisAlignment. spaceBetween, .


1 Answers

In your Code under second Column: Add - crossAxisAlignment: CrossAxisAlignment.start,

new Column(
           crossAxisAlignment: CrossAxisAlignment.start,
           children: <Widget>[],
....
like image 155
anmol.majhail Avatar answered Sep 28 '22 02:09

anmol.majhail