fromEmojiString static method

AnimatedEmojiData? fromEmojiString(
  1. String emoji
)

Return the animates emoji that equals a emoji.

When no matching animated emoji is found, null is returned.

// will return animated emoji of redHeart ❤️
final animated = AnimatedEmojis.fromEmojiString('❤️') // returns AnimatedEmojis.redHeart

Implementation

static AnimatedEmojiData? fromEmojiString(String emoji) {
  String parseEmojiCode(String str) {
    final runes = str.runes.toList();
    var code = '';
    for (var i = 0; i < runes.length; i++) {
      if (i == 0) {
        code += runes[i].toRadixString(16);
      } else {
        code += runes[i].toRadixString(16);
      }

      if (i != runes.length - 1) code += '_';
    }
    return code;
  }

  final code = parseEmojiCode(emoji);

  for (final v in AnimatedEmojis.values) {
    if (code == v.id) {
      return v;
    }
  }

  return null;
}