-1

android studio 3

  return new Container(
        height: 64.0,
        child: new Row(children: [
          new Expanded(child: new Container(color: Colors.cyanAccent,
              child: new Column(children: [
            new Text("Today",
                style: new TextStyle(
                    fontSize: 19.0,
                    color: Colors.black),
                textAlign: TextAlign.left),
            new Text("Thuersday, 26 March")
          ]))),
          new Align(alignment: Alignment.centerRight, child: new Image(image: AssetImage('assets/images/ic_profile.png')))
        ]));

as you can see to align text Today I use textAlign: TextAlign.left. But it not work.

Here result:

enter image description here

Alexei
  • 14,350
  • 37
  • 121
  • 240

2 Answers2

1

Text Align will only work if the space occupied by the text is bigger than the text itself.

Wrap your text in an Align widget to solve your issue.

return Container(
      height: 64.0,
      child: Row(
        children: [
          Expanded(
            child: Container(
              color: Colors.cyanAccent,
              child: Column(
                children: [
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Text("Today",
                        style: TextStyle(fontSize: 19.0, color: Colors.black),
                        textAlign: TextAlign.left),
                  ),
                  Text("Thuersday, 26 March")
                ],
              ),
            ),
          ),
          Align(
            alignment: Alignment.centerRight,
            child: Image(
              image: AssetImage('assets/images/ic_profile.png'),
            ),
          ),
        ],
      ),
    );

Please refer to this answer for more information.

Sam
  • 348
  • 1
  • 10
0

You have to set the crossAxisAlignment of the Column parent of your text. The width of that Column is equal to her widest child and by default crossAxisAlignment is set to CrossAxiAlignment.center.

 return Container(
        height: 64.0,
        child: Row(children: [
          Expanded(child: Container(color: Colors.cyanAccent,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
            Text("Today",
                style: new TextStyle(
                    fontSize: 19.0,
                    color: Colors.black),
                textAlign: TextAlign.left),
            Text("Thuersday, 26 March")
          ]))),
          Align(alignment: Alignment.centerRight, child: new Image(image: AssetImage('assets/images/ic_profile.png')))
        ]));

Little tip -> you can avoid to type for every Widget the key word new.

Caffo17
  • 513
  • 2
  • 10