Reputation: 12324
I'm using TextAlign
to centre one piece of text and then again to send another piece of text to the right, all contained in a Row
, but the alignment does nothing at all.
Scaffold(
body: Row(
children: <Widget>[
Text('Align Centre', textAlign: TextAlign.center),
Text('Align Right', textAlign: TextAlign.right),
],
),
);
You can see here it's ignored completely:
Upvotes: 0
Views: 936
Reputation: 378
Scaffold(
body: Row(
children: <Widget>[
Container(
width:screen_width/2,
alignment: Alignment.center,
child: Text('Align Centre',),
),
Container(
width:screen_width/2,
alignment: Alignment.centerRight,
child: Text('Align right',),
),
],
),
);
and you can get screen_widht by
double screen_width = MediaQuery.of(context).size.width;
Upvotes: 0
Reputation: 20118
Wrap Text with Expanded widget:
Scaffold(
body: Row(
children: <Widget>[
Expanded(child: Text('Align Centre', textAlign: TextAlign.center)),
Expanded(child: Text('Align Right', textAlign: TextAlign.right)),
],
),
);
By default Text takes up space only required for content.
Or what you probably want:
Scaffold(
body: Stack(
children: <Widget>[
Positioned.fill(
child: Text('Align Centre', textAlign: TextAlign.center)),
Positioned.fill(
child: Text('Align Right', textAlign: TextAlign.right)),
],
),
);
Upvotes: 0
Reputation: 824
It sounds like you are after something like this:
return Scaffold(
body: Center(
child: Row(
children: <Widget>[
SizedBox(width: MediaQuery.of(context).size.width / 3.3333333,),
Expanded(child: Text('Align Centre adding more text heree....', textAlign: TextAlign.center)),
Expanded(child: Text('Align Right', textAlign: TextAlign.right)),
],
),
),
);
By adding an empty container first into the row it pushed the Align Center text into the middle.
Edit: Instead of using an expanded widget used a sized box instead and fix the width to consume a 3rd of the view.
Upvotes: 1