Closed pagetronic closed 1 week ago
Thanks for the report @pagetronic
Can you provide flutter version on which you are seeing this behavior ?
TextAlign.justify
for html renderer was added as part of https://github.com/flutter/flutter/issues/88270
thanks for your consideration
Flutter version 3.19.6
Steps to reproduce
SelectableText.rich( TextSpan(text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."), textAlign: TextAlign.justify, )
Thanks for the update. With this code snippet, below are the current results:
I see difference of a word that starts from next line using html, but another word using canvaskit. Is this the difference you are pointing to as not expected ?
Lines that end with hard line breaks are aligned towards the [start] edge.
Ok, sorry I understand now.
Only the last line is "start" aligned in Text.rich. If we place successions of TextSpan there, which have last lines, they do not consider an alignment on their own last line.
You must use Collum() and nest Text.rich to each section of text that you want to align TextAlign.justify.
On the other hand this poses a big problem for SelectableText.rich you have to use SelectableRegion instead.
Do not do :
SelectableText.rich(
TextSpan(children: [
for (int i = 0; i < 5; i++)
TextSpan(children: [
for (int i = 0; i < 5; i++)
TextSpan(text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " * 5),
TextSpan(text: "\n\n"),
]),
]),
textAlign: TextAlign.justify,
)
Do :
SelectableRegion(
focusNode: FocusNode(),
selectionControls: materialTextSelectionControls,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (int i = 0; i < 5; i++) ...[
Text.rich(
TextSpan(
children: [
for (int i = 0; i < 5; i++)
TextSpan(text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " * 5),
],
),
textAlign: TextAlign.justify,
),
Text("\n")
],
],
),
)
It even seems much better in terms of performance
Seems like you have resolved the issue. Closing based on it. If you disagree, write in comments and I'll reopen it.
When I try to TextAlign justify a Text.rich with Web export, on a web-renderer canvaskit there is no problem, but with a html renderer the last line is not aligned to "start".
In CSS it would have been necessary to put "text-align-last: left;"
Steps to reproduce
Expected results
Actual results
Code sample
Code sample
```dart @override Widget build(BuildContext context) { if (text == null) { return const SizedBox.shrink(); } List