π A light-weight Emoji π¦ for Dart & Flutter with all up-to-date emojis written in pure Dart π . Made from π―% β with β€οΈ!
This is a fork of flutter_emoji, which is inspired by the node-emoji package. The reason for the fork is better maintaining and adding further features, such as EmojiUtil.hasOnlyEmojis()
.
dart_emoji
is even used in production for our app Gatch. You can get Gatch for iOS and Android.
First, import the package:
import 'package:dart_emoji/dart_emoji.dart';
There are two main classes you need to know to handle Emoji text: Emoji
and EmojiParser
.
Basically, you need to initialize an instance of EmojiParser
.
var parser = EmojiParser();
var coffee = Emoji('coffee', 'β');
var heart = Emoji('heart', 'β€οΈ');
// Get emoji info
var emojiHeart = parser.info('heart');
print(emojiHeart); '{name: heart, full: :heart:, code: β€οΈ}'
// Check emoji equality
heart == emojiHeart; // returns: true
heart == emojiCoffee; // returns: false
// Get emoji by name or code
parser.get('coffee'); // returns: Emoji{name="coffee", full=":coffee:", code="β"}
parser.get(':coffee:'); // returns: Emoji{name="coffee", full=":coffee:", code="β"}
parser.hasName('coffee'); // returns: true
parser.getName('coffee'); // returns: Emoji{name="coffee", full=":coffee:", code="β"}
parser.hasEmoji('β€οΈ'); // returns: true
parser.getEmoji('β€οΈ'); // returns: Emoji{name="heart", full=":heart:", code="β€οΈ"}
parser.emojify('I :heart: :coffee:'); // returns: 'I β€οΈ β'
parser.unemojify('I β€οΈ β'); // returns: 'I :heart: :coffee:'
// Check if text contains only emojis
EmojiUtil.hasOnlyEmojis("π"); // returns true
EmojiUtil.hasOnlyEmojis("π Hello"); // returns false
All methods will return Emoji.None
if emoji is not found.
parser.get('does_not_exist_emoji_name'); // returns: Emoji.None
MIT @ 2021 Gatch GmbH.