This article shows you 2 ways to display text that contains special characters in Flutter.
1. Escaping every special character
Like many programming languages, you can escape special characters in a Dart string by using (backslash). Advertisements
body: Center( child: Text('This book costs $1000', style: TextStyle(fontSize: 30),) )
2. Display text as a raw string
You can create a raw string by prefixing it with r.
body: Center( child: Text(r'I gave my son $5 yesterday', style: TextStyle(fontSize: 20),) )
At this point, you should have a better understanding of displaying special characters with the Text widget in Flutter. If youd like to learn more about Flutter and Dart, take a look at the following articles:
- Adding a Border to Text in Flutter
- Flutter: Stream.periodic example
- Flutter TextField: Styling labelText, hintText, and errorText
- Flutter & Dart: Regular Expression Examples
- Sorting Lists in Dart and Flutter (5 Examples)
You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.