emoji_picker_flutter

repository·master·Indexed 41 days ago

https://github.com/fintasys/emoji_picker_flutter

A lightweight, highly customizable emoji picker for Flutter applications. It supports Material and Cupertino modes, skin tone selection, search functionality, and localization for multiple languages. The package provides the EmojiPicker widget and a comprehensive Config object to customize the emoji view, category tabs, bottom action bar, and search interface.

Tokens
10.5K
Snippets
31
Records
41
Agent score
52%

What's inside emoji_picker_flutter

  1. Implement the EmojiPicker widget

    master

    To integrate the emoji picker into your Flutter application, use the EmojiPicker widget. You must provide a textEditingController that is the same instance used by your input field (e.g., a TextFormField) to ensure emojis are correctly inserted into the text.

    Key parameters:

    • onEmojiSelected: Callback triggered when an emoji is tapped. Receives the Category and the Emoji object.
    • onBackspacePressed: Callback triggered when the backspace button is tapped. Set to null to hide the backspace button.
    • textEditingController: The controller connected to your text input.
    • controller: (Optional) An EmojiPickerController to programmatically control category tabs.
    • config: A Config object used to customize the appearance and behavior of the picker.
    import 'package:flutter/foundation.dart' as foundation;
    
    EmojiPicker(
        onEmojiSelected: (Category category, Emoji emoji) {
            // Do something when emoji is tapped (optional)
        },
        onBackspacePressed: () {
            // Do something when the user taps the backspace button (optional)
            // Set it to null to hide the Backspace-Button
        },
        textEditingController: textEditingController, // pass here the same [TextEditingController] that is connected to your input field, usually a [TextFormField]
        controller: emojiPickerController, // (Optional) Allows you to control and maintain state of category tabs
        config: Config(
            height: 256, // Set `null` to unconstrain emoji picker
            bgColor: const Color(0xFFF2F2F2),
            checkPlatformCompatibility: true,
            emojiViewConfig: EmojiViewConfig(
            // Issue: https://github.com/flutter/flutter/issues/28894
            emojiSizeMax: 28 * 
            (foundation.defaultTargetPlatform == TargetPlatform.iOS
                ?  1.20
                :  1.0),
            ),
            viewOrderConfig: const ViewOrderConfig(
                top: EmojiPickerItem.categoryBar,
                middle: EmojiPickerItem.emojiView,
                bottom: EmojiPickerItem.searchBar,
            ),
            skinToneConfig: const SkinToneConfig(),
            categoryViewConfig: const CategoryViewConfig(),
            bottomActionBarConfig: const BottomActionBarConfig(),
            searchViewConfig: const SearchViewConfig(),
        ),
    )
  2. Localize the Emoji Picker

    master

    The package supports en, de, es, fr, hi, it, ja, pt, ru, and zh.

    To use a specific language, pass the Locale to the Config. To support custom languages, you must provide a custom emojiSet via a function that returns List<CategoryEmoji> based on the provided Locale.

    // Using a built-in locale
    Config(
        locale: const Locale("ja"),
    )
    
    // Using a custom emoji set for localization
    EmojiPicker(
        config: Config(
             emojiSet: _getEmojiLocale,
        ),
    )
    
    List<CategoryEmoji> _getEmojiLocale(Locale locale) {
      switch (locale.languageCode) {
        case "ja":
          return emojiSetJapanese;
        case "de":
          return emojiSetGerman;
        default:
          return emojiSetEnglish;
      }
    }
  3. Customize the Backspace Button position

    master

    The backspace button is enabled by default in the BottomActionBarConfig. To move it to the category tab bar instead, configure CategoryViewConfig with extraTab: CategoryExtraTab.BACKSPACE.

    You can handle tap events using the onBackspacePressed callback in the EmojiPicker constructor.

  4. Configure the main EmojiPicker Config

    master

    The Config object is the central way to customize the EmojiPicker. Use these properties to control layout, styling, and platform behavior.

    propertydescriptiondefault
    heightHeight of Emoji Picker (set to null to make widget unconstrained)256
    viewOrderConfigThe exact order in which category view, emoji view and bottom bar appearconst ViewOrderConfig()
    checkPlatformCompatibilityWhether to filter out glyphs that platform cannot render with the default font (Android).true
    emojiSetCustom emoji set, can be built based on defaultEmojiSet provided by the library.null
    emojiTextStyleText style to apply to individual emoji icons. Can be used to define custom emoji font either with GoogleFonts library or bundled with the app.null
    customBackspaceIconCustom Icon for Backspace buttonnull
    customSearchIconCustom Icon for Search buttonnull
    emojiViewConfigEmoji view configconst EmojiViewConfig()
    skinToneConfigSkin tone configconst SkinToneConfig()
    categoryViewConfigCategory view configconst CategoryViewConfig()
    bottomActionBarConfigBottom action bar configconst BottomActionBarConfig()
    searchViewConfigSearch View configconst SearchViewConfig()
  5. Configure the Category View

    master

    Use CategoryViewConfig to customize the category tab bar. Key properties include:

    • tabBarHeight: Height of the tab bar (default: 46.0).
    • initCategory: The initial selected Category (default: Category.RECENT).
    • recentTabBehavior: Controls showing the recently/popular used emoji tab (default: RecentTabBehavior.RECENT).
    • extraTab: Adds an extra tab for backspace or search (e.g., CategoryExtraTab.BACKSPACE).
    • backgroundColor, indicatorColor, iconColor, iconColorSelected: Visual styling for the bar and icons.
    • categoryIcons: Customizes icons for each Category using CategoryIcons().
  6. Configure SkinToneConfig and persist skin tones

    master

    The SkinToneConfig allows you to manage how skin tones are displayed and remembered.

    propertydescriptiondefault
    enabledEnable feature to select a skin tone of certain emoji'strue
    dialogBackgroundColorThe background color of the skin tone dialogColors.white
    indicatorColorColor of the small triangle next to multiple skin tone emojiColors.grey
    rememberSkinToneRemember the last selected skin tone and re-apply it as the defaultfalse

    Remembering a chosen skin tone

    By default the grid, recents and search render the base (default) glyph. Set rememberSkinTone: true to have the picker persist the last tone chosen via the long-press picker (stored in SharedPreferences) and re-apply it as the default for every skin-tone-capable emoji on the next launch. Selecting the base (no-tone) glyph clears the remembered tone.

    SkinToneConfig(
      rememberSkinTone: true,
    ),
  7. Configure the Search View

    master

    Use SearchViewConfig to customize the search interface. Key properties include:

    • backgroundColor: Background color (default: const Color(0xFFEBEFF2)).
    • buttonColor: Fill color of the hide search view button (default: Colors.transparent).
    • buttonIconColor: Icon color of the hide search view button (default: Colors.black26).
    • hintText: Custom hint text (default: 'Search').
    • customSearchView: Allows providing a completely custom widget.
  8. Configure the Bottom Action Bar

    master

    Use BottomActionBarConfig to customize the bottom bar. Key properties include:

    • showBackspaceButton: Toggles the backspace button (default: true).
    • showSearchViewButton: Toggles the search view button (default: true).
    • backgroundColor: Background color of the bar (default: Colors.blue).
    • buttonIconColor: Color for the action buttons (default: Colors.white).
    • inputTextStyle / hintTextStyle: Custom TextStyle for the text field.
    • customBottomActionBar: Allows providing a completely custom widget.
  9. Configure the EmojiViewConfig

    master

    Use EmojiViewConfig to customize the grid of emojis.

    propertydescriptiondefault
    columnsNumber of emojis per row7
    emojiSizeMaxWidth and height the emoji will be maximal displayed32.0
    backgroundColorThe background color of the emoji viewconst Color(0xFFEBEFF2)
    verticalSpacingVertical spacing between emojis0
    horizontalSpacingHorizontal spacing between emojis0
    gridPaddingThe padding of GridViewEdgeInsets.zero
    recentsLimitLimit of recently used emoji that will be saved28
    replaceEmojiOnLimitExceedReplace latest emoji on recents list on limit exceedfalse
    noRecentsA widget (usually [Text]) to be displayed if no recent emojis to display. Needs to be const Widget!Text('No Recents', style: TextStyle(fontSize: 20, color: Colors.black26), textAlign: TextAlign.center)
    loadingIndicatorA widget to display while emoji picker is initializing. Needs to be const Widget!SizedBox.shrink()
    buttonModeChoose between Material and Cupertino button styleButtonMode.MATERIAL
  10. Customize emoji text style and platform compatibility

    master

    You can provide a custom emojiTextStyle to apply specific fonts or sizes to emoji characters in the grid.

    Important: If you use a custom fontFamily or GoogleFonts via emojiTextStyle, you should set checkPlatformCompatibility to false. This prevents the picker from filtering out technically supported glyphs and improves initialization performance.

  11. Use a custom font with EmojiPicker

    master

    You can customize the appearance of the emoji picker by providing a custom font. This is useful for ensuring emoji consistency across different platforms or matching a specific application design language.

    // Refer to the custom font example implementation in the repository
    // https://github.com/Fintasys/emoji_picker_flutter/tree/master/example/lib/main-custom-font.dart
  12. Basic usage of EmojiPicker

    master

    The simplest way to integrate the emoji picker is to use the default configuration. This provides a standard emoji selection interface within your Flutter application.

    // Refer to the simple example implementation in the repository
    // https://github.com/Fintasys/emoji_picker_flutter/tree/master/example/lib/main.dart