π A light-weight Emoji π¦ for Flutter and Dart-based applications with all up-to-date emojis π. Made from π―% β with β€οΈ!
Inspired from the node-emoji package.
Update: since v2.3.4+, support all emojis listed in Unicode 13.0.
NOTE: I initially created this package to support my Flutter apps. However, Dart is growing to support on more platforms, so starting from v2.4.0+, this package will be available to all types of Dart-based applications.
I'm working on the new version of the package, it might or might not introduce breaking changes but I will try to maintain the compatibility in the API.
Here are few upcoming update to the v3:
- Support Unicode 15.1+ emojis.
- Skin tone
- Group (category) of the emojis
- Emoji version
- Few new methods for handling/manipulating emojis.
Add this into pubspec.yaml
dependencies:
flutter_emoji: ">= 2.0.0"
First, import the package:
import 'package:flutter_emoji/flutter_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
and call its methods.
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:'
// Count number of present emojis
parser.count('I β€οΈ Flutter just like β'); // returns: 2
// Count frequency of a specific emoji
parser.frequency('I β€οΈ Flutter just like β', 'β€οΈ'); // returns: 1
// Replace a specific emoji by another emoji
parser.replace('I β€οΈ coffee', 'β€οΈ', 'β€οΈβπ₯'); // returns: 'I β€οΈβπ₯ coffee'
// Get a list of all emojis from the input
parser.parseEmojis('I β€οΈ Flutter just like β'); // returns: ['β€οΈ', 'β']
All methods will return Emoji.None
if emoji is not found, except these two emojify()
and unemojify()
that will return original input.
parser.get('does_not_exist_emoji_name'); // returns: Emoji.None
There are two available datasets available you can choose to initialize for EmojiParser
: local and server.
// to load local dataset
var localParser1 = EmojiParser();
var localParser2 = EmojiParser(init: false);
localParser2.initLocalData();
// to load server dataset
// this will trigger an URL request to download latest emoji data
var serverParser = EmojiParser(init: false);
await serverParser.initServerData(); // make sure to wrap in an `async` function/method.
NOTE: make sure to add Internet permission on Android.
<!-- Required to fetch data from the internet. -->
<uses-permission android:name="android.permission.INTERNET" />
In any occasion that local dataset doesn't have the latest emojis, load server dataset instead. If it is still not working, please create an issue or pull request to the repo.
Features coming to this package:
- Get detail of an emoji.
- Refactor for easier usage.
- Validate bad input.
- Find list of available emojis from a given text.
- Replace emoji by another one.
- Callback for additional formatting found emojis.
- Ability to fetch latest emoji list.
- Make extensible emoji matcher.
MIT @ 2019 Pete Houston.