Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text read from disk does not comply with new line character

Tags:

flutter

dart

Using the Text widget with text that's read from disk, that contains new line characters \n, does not go to new line. Anyone have suggestions of how I can get around this? The text in the file is enter image description here

The code for the image you see above is as follows:

Text(valueFromFile, style: TextStyle(color: Colors.red))

My text is being read from an Xml file that is contained in my assets folder.

like image 360
Filled Stacks Avatar asked Sep 16 '25 23:09

Filled Stacks


1 Answers

The comment from uaraven above

Does your file contain actual '\n' characters? If so then that's not a new line character ...

Helped me come up with a solution. Since the Text Widget is interpreting the \n characters as normal characters, I just did a replace on it and inserted the actual escape character.

var correctlyEscapedString = valueFromFile.replaceAll('\\n', '\n');
Text(correctlyEscapedString, style: TextStyle(color: Colors.red));
like image 163
Filled Stacks Avatar answered Sep 19 '25 15:09

Filled Stacks