Good evening Stack Overflow.
Any advances on this Flutter code to achieve vertically-centered, but left-aligned text, in a simple full width container?
I found I had to fall back on making a secondary wrapper column around the text, and set BOTH mainAxisAlignment.center (for horizontal centering) and crossAxisalignment.start (to get left alignment).
I don;t want to set the Main column's axis alignments, as there will be other text widgets with different text alignments.
For the wrapper column I made it seems I can't just set mainAxisAlignment.center (for horizontal center) and then force textAlign.left in the Text widget itself. Surprised by that.
Anyway, the below code works, but surely there's a more efficient way?
body: SafeArea(
child: Column( //<-MAIN column for everything on the page
children: <widget> [
// A container for my text widget
Container(
height: 50;
width: double.infinity,
Child: Column( //<- had to make another wrapper column.
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
Children: [
Text('mytext')
]
),
) //container
] //children
)) //Main column and SafeArea
Cheers.
CodePudding user response:
wrap your Text Widget in an Align Widget and set the alignment to centerLeft
