4

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?

2
  • 6
    Try: final result = String.fromCharCode(iconData.codePoint); Commented Aug 18, 2020 at 15:48
  • That's right, thank you very much! Commented Aug 18, 2020 at 15:56

1 Answer 1

5

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.