Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter/Dart programmatically unicode string

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?

like image 744
Marco A. Braghim Avatar asked Oct 23 '25 22:10

Marco A. Braghim


1 Answers

Here's the right answer. I tried everything but this... Thank you @julemand101

final result = String.fromCharCode(iconData.codePoint);

like image 139
Marco A. Braghim Avatar answered Oct 25 '25 13:10

Marco A. Braghim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!