Fintasys / emoji_picker_flutter

A Flutter package that provides an Emoji picker widget with 1500+ emojis in 8 categories.
MIT License
154 stars 114 forks source link

Match An Emoji in String #140

Closed danishrafiqe closed 6 months ago

danishrafiqe commented 1 year ago

How to match emoji in text Field Basically i want to check My Typed Message is only Emoji or with text

Fintasys commented 1 year ago

The package doesn't offer a direct helper method for that but you should be able to just check your text with regex for words or letters. Or seems there is also a package called emoji_regex, not sure if it is helpful tho.

Fintasys commented 6 months ago

A bit complex, but it should be possible to create this regex and then check every character in your string

    final regExBuffer = StringBuffer();
    for (final list in defaultEmojiSet) {
      for (final emoji in list.emoji) {
        // Put emoji inclusive skin tone before actualy emoji
        // to avoid color and emoji being seperated
        if (emoji.hasSkinTone) {
          for (final skinTone in SkinTone.values) {
            regExBuffer.write(
              '${utils.applySkinTone(emoji, skinTone).emoji}$delimiter',
            );
          }
        }
        regExBuffer.write('${emoji.emoji}$delimiter');
      }
    }
    final regExString = regExBuffer.toString();
    RegExp regex = RegExp(regExString.substring(0, regExString.length - 1));