Magesh Pandian
Magesh Pandian

Reputation: 9369

How do align text vertical in flutter?

I like to know, how to align text vertical in Text Widget. There is an attribute called textAlign. It will align the text center of both vertical and horizontal. So I need to algin text only in vertical.

When I set TextAlign.center,

enter image description here

Upvotes: 0

Views: 284

Answers (3)

iamrishan
iamrishan

Reputation: 104

wrap your text inside a Align widget,

so you can control the alignment in any direction horizontal or vertical or both

see result

Container(
        height: 48,
        width: double.infinity,
        decoration:
            BoxDecoration(border: Border.all(width: 1, color: Colors.blue)),
        child: const Align(
          alignment: Alignment.centerLeft,
          child: Text(
            'Hello World',
          ),
        ),
      ),

Upvotes: 0

Alok
Alok

Reputation: 8978

You may also use Row() Flutter or Column() and use their crossAxisAlignment and mainAxisAlignment for alignment of the widget

Column(
  crossAixsAlignment: CrossAxisAlignment.center,
  children: <Widget>[ Text() ]
)

Upvotes: 1

BambinoUA
BambinoUA

Reputation: 7100

The Text widget can be aligned in some parent widget (eg. Container, Center etc). Or you may wrap Text with Align widget.

Upvotes: 1

Related Questions