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
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.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With