I want to vertically and horizontally center a text within a white container in flutter.
Code I used to generate the following example but it is not vertically centered. Any idea how to?
return Center(
child: Container(
color: Colors.white,
width: 105,
height: 105,
child: Align(
alignment: Alignment.center,
child: Container(
color: Colors.green,
child: Text(
'1',
style: TextStyle(fontSize: 100),
),
),
),
),
);
>Solution :
In your code, the Text widget is already centered vertically, but the text itself has some line height that makes it looks like there is some space on the top.
From the documentation of height property of TextStyle:
If you set the height to 1.1 for example, you can see it now looks centered:
Text(
'1',
style: TextStyle(
fontSize: 100,
height: 1.1,
),
)
References:


