'Flutter unicode number to emoji
I want to display a string in Text widget within which are some emojis. But the string is in the format of unicode number, like "U+1F44C". I am trying to display it as emoji characters:👌.
I tried to format the string as \u{xxxx}:
final str = "\\u{${unicodeString}}";
but it does not work. It only shows the original string \u{1f44c}
Solution 1:[1]
This is showing \u{1f44c} because when you specify multiple backslash like \\u then flutter/dart consider the whole text as a normal string type data.
If you specify \u then flutter expects that the next characters would be the hexadecimal special characters and consider this string as hexadecimal special characters string data when flutter render the text to UI, during this time flutter engine convert the hexadecimal special characters string and render the corresponding emoji.
So you should use the actual hexadecimal special characters string like final str = "\u{1f44c}";
Solution 2:[2]
You can simply copy the Emoji and paste it between '' or "" like this:
final str = "?";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Erlend Johnsen |
