Flutter Align right: not align right for multiple line text.
SizedBox(
width: 108,
child: Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Text('Billing Address:'),
)),
);
When the text "Billing Address:" is rendered as two lines, it is aligned left, not right.
---------------
Billing |
Address: |
---------------
It works for one line, e.g., "Name:"
---------------
Name: |
---------------
>Solution :
In the "Name:" case, the Text widget takes only the required width for its text to fit, so it looks correctly aligned to the top-right of the parent widget.
In the "Billing Address:" case, the Text widget has its size reached the maximum width available, so it’s actually aligned to the top-right correctly by the Align widget. However, the internal text itself is still aligned to the start (left, in LTR direction) by default.
You have to align the text inside the Text widget itself, by setting the textAlign to TextAlign.end (when using LTR direction):
Text(
// ...
textAlign: TextAlign.end,
)