Home > Blockchain >  Emojis length error when Text() - flutter
Emojis length error when Text() - flutter

Time:11-08

I'm trying to show all of the emojis that I have on a JSON file (I stored their Unicode and their description). However, as Flutter cannot check that my keys (the unicode) have a length of 4 it shows an error. What can I do?

myEmoji = "\u{$key}";

ERROR: Error: An escape sequence starting with '\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'.

EDIT: the key stored looks something like this : "1F601"

CodePudding user response:

\u is used for a Unicode literal; it is parsed at compile-time. It cannot be used with a variable.

If you have a String with the hexadecimal representation of the Unicode code point, you will need to parse that String to an integer value and then use String.fromCharCode:

void main() {
  var codePointString = '1F601';
  var codePointValue = int.parse(codePointString, radix: 16);
  var emoji = String.fromCharCode(codePointValue);
  print(emoji); // Prints:            
  • Related