getEmojiDefinitions function
List all the emoji definitions currently available.
This method caches results for 4 hours.
Implementation
Future<List<EmojiDefinition>> getEmojiDefinitions() async {
if (_cachedEmojiDefinitions != null && _cachedAt!.add(Duration(hours: 4)).isAfter(DateTime.timestamp())) {
return _cachedEmojiDefinitions!;
} else {
final response = await http.get(_emojiDefinitionsUrl);
final data = jsonDecode(utf8.decode(response.bodyBytes))['emojiDefinitions'];
_cachedAt = DateTime.timestamp();
return _cachedEmojiDefinitions = [
for (final raw in data)
EmojiDefinition(
primaryName: raw['primaryName'] as String,
names: parseMany(raw['names'] as List),
surrogates: raw['surrogates'] as String,
utf32Codepoints: parseMany(raw['utf32codepoints'] as List),
assetFilename: raw['assetFileName'] as String,
assetUrl: Uri.parse(raw['assetUrl']),
category: raw['category'] as String,
alternateSurrogates: raw['alternativeSurrogates'] as String?,
alternateUtf32Codepoints: maybeParseMany(raw['alternativeUtf32codepoints']),
),
];
}
}