Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emojis in VSCode

Im trying to edit the following array of emojis in dart, I tried emoji extensions in VSCode but none are working for this line of code.

const _emojis = ['πŸ˜ƒ','πŸ€“','😁','πŸ˜‚','😞'];

like image 591
Sam Cromer Avatar asked Oct 18 '25 09:10

Sam Cromer


1 Answers

Dart Strings appear to be UTF-16 sequences. So find the UTF sequences for those emoji and use them as described in that link.

The simplest naΓ―ve case, that of Unicode code points, would be:

const _emojis = ['\u{1f605}','\u{1f606}','\u{1f607}','\u{1f608}','\u{1f609}'];

for (var i = 0;i<_emojis.length;i++) {
   print("Position $i : ${_emojis[i]} ");
}

There are helpers for this as well:

For a character outside the Basic Multilingual Plane (plane 0) that is composed of a surrogate pair, runes combines the pair and returns a single integer

In fact, you are recommended to not use raw lists for this as it can lead to problems down the road. The Language Tour specifically calls this out:

Note: Be careful when manipulating runes using list operations. This approach can easily break down, depending on the particular language, character set, and operation.

Also, see the Dart String tutorial and the Language Tour (which actually shows a solution to this exact question).