Musa Usman
Musa Usman

Reputation: 711

FLUTTER | Right Align not working

Trying to right align a container with text view child, it has a row parent which is inside another column, tried number of solutions from Stack Overflow, didn't work.

Code

///Transactions Heading
        new Column(
         children: <Widget>[
            new Row(
              children: <Widget>[
                new Container(
                  alignment: Alignment.centerLeft,
                  margin: new EdgeInsets.only(top: 20.0, left: 10.0),
                  child: new Text(
                    "Transactions",
                    style: new TextStyle(
                      color: primaryTextColor,
                      fontSize: 25.0,
                      fontWeight: FontWeight.w700,
                      letterSpacing: 0.1,
                    ),
                  ),
                ),
                new Container(
                  margin: new EdgeInsets.only(top: 25.0),
                  child: new Text(
                    currentGoalTransactions.length.toString() + " items",
                    style: new TextStyle(
                        color: darkHeadingsTextColor, fontSize: 15.0),
                  ),
                ),
              ],
            ),
       ]);

Want to align the 2 items text to the right

Screenshot

Upvotes: 27

Views: 46972

Answers (3)

Jitesh Mohite
Jitesh Mohite

Reputation: 34210

Use Spacer which will get remaining space and will divide the widget equally

     Row(
        children: <Widget>[
          Text("Text 1", style: TextStyle(fontSize: 20),),
          Spacer(),
          Text("Text 2", style: TextStyle(fontSize: 20),),
          Spacer(),
          Text("Text 3", style: TextStyle(fontSize: 20),),
        ],
      ),

Output:

enter image description here

Upvotes: 8

CopsOnRoad
CopsOnRoad

Reputation: 267594

Screenshot:

enter image description here


You can also try Wrap like this:

Wrap(
  spacing: 50, // spacing between each of the widgets below
  children: <Widget>[
    Text("One"),
    Text("Two"),
    Text("Three"),
  ],
)

Upvotes: 2

Vinoth Kumar
Vinoth Kumar

Reputation: 13431

Use the mainAxisAlignment property in Row widget.

new Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween, 
    ...
)

Upvotes: 50

Related Questions