Flutter/Dart programmatically unicode string
Here's the right answer. I tried everything but this... Thank you @julemand101
final result = String.fromCharCode(iconData.codePoint);
Marco A. Braghim
Updated on December 23, 2022Comments
-
Marco A. Braghim over 1 year
I have a list of customized icons to my app, it comes like below setted as IconData, note
codePoint
(0xe931).IconData angry_face = IconData(0xe931, fontFamily: _fontFamily);
There's nothing wrong with that, but I've some cases where I need this icon as Unicode string to be used as a text. It should be done just like:
// It works too Text('\ue931', style: TextStyle(fontFamily: _fontFamily));
The problem is:
I don't wanna use this code "by hand" because this icons are changed constantly by designers team and sometimes it changes its code messing up my app icons. What I need to do is get the icon object and parse it to the Unicode string, so I can use it with a Text widget.
I thought that would work to get programmatically that code and just use it, but it don't:
var iconcode = iconData.codePoint.toRadixString(16); var result; // Error: An escape sequence starting with '\u' // must be followed by 4 hexadecimal digits or // from 1 to 6 digits between '{' and '}' result = '\u$iconcode'; // Just a simple string result = '\\u$iconcode';
In few words: How can I parse programmatically int codePoint to a valid Unicode string?
-
julemand101 over 3 yearsTry:
final result = String.fromCharCode(iconData.codePoint);
-
Marco A. Braghim over 3 yearsThat's right, thank you very much!
-