Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I center text vertically and horizontally in Flutter?

People also ask

How do you center text horizontally in Flutter?

Flutter – Center Align Text in Text Widget To center align the text in a Text widget, provide textAlign property with value TextAlign. center .

How do you center text horizontally and vertically?

Select the text that you want to center. in the Page Setup group, and then click the Layout tab. In the Vertical alignment box, click Center. In the Apply to box, click Selected text, and then click OK.

How do you align text right in Flutter?

right aligns the text left and right inside its boundaries respectively. TextAlign. justify horizontally justifies the text over its container. textDirection: textDirection is used to specify the direction of the text inside a Text Widget say ltr (left-to-right) or rtl (right to left).


Text alignment center property setting only horizontal alignment.

enter image description here

I used below code to set text vertically and horizontally center.

enter image description here

Code:

      child: Center(
        child: Text(
          "Hello World",
          textAlign: TextAlign.center,
        ),
      ),

You can use TextAlign property of Text constructor.

Text("text", textAlign: TextAlign.center,)

I think a more flexible option would be to wrap the Text() with Align() like so:

Align(
  alignment: Alignment.center, // Align however you like (i.e .centerRight, centerLeft)
  child: Text("My Text"),
),

Using Center() seems to ignore TextAlign entirely on the Text widget. It will not align TextAlign.left or TextAlign.right if you try, it will remain in the center.


                       child: Align(
                          alignment: Alignment.center,
                          child: Text(
                            'Text here',
                            textAlign: TextAlign.center,                          
                          ),
                        ),

This produced the best result for me.


U need to use textAlign property on the Text widget. It produced the best results for me

Text(
  'Hi there',
   textAlign: TextAlign.center,                          
 )