Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter \n\n not breaking lines unless hard-coded string

I can see that Flutter allows me to use "\n\n" in a string and it causes a line break to appear in a Text item:

final String answer = "This is my text.\n\n"
    "Here is the 2nd line.";

This is my text.

Here is the 2nd line.

However, when I try to use content pulled from firebase, and set in a variable, the line break ("\n") is actually printed:

final String answer = faq['answer'];

Shows:

This is my text.\n\nHere is the 2nd line.

How can I get my "\n\n" to actually show up as line breaks?

like image 982
Dave Avatar asked Apr 08 '19 00:04

Dave


People also ask

How do you break a line in a Flutter string?

A StreamTransformer that splits a String into individual lines. A line is terminated by either: a CR, carriage return: U+000D ('\r') a LF, line feed (Unix line break): U+000A ('\n') or.

How do I force a line break in CSS?

A line-break can be added in HTML, using only CSS, by employing the pseudo-class ::after or ::before . In the stylesheet, we use these pseudo-classes, with the HTML class or id, before or after the place where we want to insert a line-break. In myClass::after : Set the content property to "\a" (the new-line character).

How do you add a break to text in Flutter?

Sometimes we have so much text in flutter mobile application and all the text seems to pushing each other. But using the \n(Backward slash with Small n) character we can Break Text Line From Middle in Flutter Android iOS mobile app.

How do you make a new line in Flutter?

Approach 2 Using \n here is an example with Dynamic String : var readLines = ['Test1', 'Test2', 'Test3']; String getNewLineString() { StringBuffer sb = new StringBuffer(); for (String line in readLines) { sb. write(line + "\n"); } return sb.


1 Answers

Firestore doesn't support any escape sequences within string values. If you write "\n" in a string, you're going to get exactly that back when you read it.

So you can try something like this:

final String answer = (faq['answer'] as String).replaceAll("\\n", "\n");
like image 184
diegoveloper Avatar answered Oct 12 '22 02:10

diegoveloper