Flutter: Displaying text that contains special characters

Updated: August 24, 2023 By: A Goodman 3 comments

This article shows you a couple of different ways to display text that contains special characters in Flutter.

Escaping every special character

Like many programming languages, you can escape special characters in a Dart string by using \ (backslash).

Example:

body: const Center(
          child: Text('This book costs \$1000', 
                          style: TextStyle(fontSize: 30),)
)

Output:

Display text as a raw string

You can create a raw string by prefixing it with r.

Example:

body: const Center(
          child: Text(r'I gave my son $5 yesterday', 
                          style: TextStyle(fontSize: 20),)
)

Output:

Conclusion

At this point, you should have a better understanding of displaying special characters with the Text widget in Flutter. If you’d like to learn more about Flutter and Dart, take a look at the following articles:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Subscribe
Notify of
guest
3 Comments
Inline Feedbacks
View all comments
wsss
wsss
2 years ago

dsds

jagdish@getnada.com
2 years ago

its gave not gived

Related Articles