Implement the EmojiPicker widget
masterTo 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 theCategoryand theEmojiobject.onBackspacePressed: Callback triggered when the backspace button is tapped. Set tonullto hide the backspace button.textEditingController: The controller connected to your text input.controller: (Optional) AnEmojiPickerControllerto programmatically control category tabs.config: AConfigobject 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(),
),
)