Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does flutter's Text widget let it display all spaces that end with a space?

Tags:

flutter

Container(
    decoration: BoxDecoration(
      color: Colors.blue,
      border: Border.all(width: 1.0,color: Colors.red)
    ),
    child: Text('11111111               '),
  ),

When I look at the effect of this Container, all the spaces after 111... are not displayed, unless I add a non-space character at the end. How can I solve this?

like image 865
long Avatar asked Aug 24 '18 07:08

long


1 Answers

It looks like at the moment, the trailing whitespaces can't be kept in any way, since they are removed at a lower level, by the Flutter engine in C++, when calculating the line breaks.

A Text is actually a RichText which contains a TextSpan, itself rendered by a ParagraphBuilder belonging to dart:ui (link here). And the thing is that when the paragraph is rendered, line breaks are calculated by a third party member of the Flutter engine, which remove every trailing spaces (link here, see line 173).

I'd suggest to fill a new issue on Github to mention that.

like image 91
Jonathan Avatar answered Nov 07 '22 11:11

Jonathan