dart_emoji
This is a fork from flutter-emoji, which is inspired from the node-emoji package.
flutter-emoji
?
Why is this a fork from flutter-emoji |
dart-emoji |
|
---|---|---|
Still maintained? | |
|
Null Safety | |
|
Pure Dart Package | |
|
Updated emojis | |
|
dart-emoji
is even used in production for our app Gatch. You can get Gatch for iOS and Android.
Installation
Add this into pubspec.yaml
dependencies:
dart_emoji: ^0.1.0
API Usage
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.hasTextOnlyEmoji("๐"); // returns true
EmojiUtil.hasTextOnlyEmoji("๐ Hello"); // returns false
All methods will return Emoji.None
if emoji is not found.
parser.get('does_not_exist_emoji_name'); // returns: Emoji.None
License
MIT @ 2021 Gatch GmbH.