Reputation: 12336
I want to align the small text so it is flush with the right edge of the larger text above but TextAlign
is ignored unless you add a width in Container
around the individual text widget.
Container(
child: Column(
children: <Widget>[
Text('One', style: TextStyle(fontSize: 40)),
Text('Two', textAlign: TextAlign.right, style: TextStyle(fontSize: 30)),
],
),
),
I can't set a width since then it will not be the same for different devices. It should simply align right based on the width of the larger text above but it doesn't.
A width value should not be necessary since the width should be set by the width of the larger text, but without a width value TextAlign
is ignored for some strange reason.
I need it to look like this:
Upvotes: 2
Views: 3217
Reputation: 6010
We can combine CrossAxisAlignment.stretch
for Column widget and IntrinsicWidth widget. IntrinsicWidth
Sizes its child's width to the child's maximum intrinsic width.
Center(
child:
Container(
child:
IntrinsicWidth(
child:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('The title', style: TextStyle(fontSize: 40)),
Text('small', textAlign: TextAlign.right, style: TextStyle(fontSize: 30)),
],
)))
PS Perhaps you dont need Container widget here
Upvotes: 4