Flutter – Center Align Text in Text Widget To center align the text in a Text widget, provide textAlign property with value TextAlign. center .
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.
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.
I used below code to set text vertically and horizontally center.
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,
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With