From eb5e97fe1a8598625244e7386a0283854415fc3c Mon Sep 17 00:00:00 2001 From: Stefan Humm Date: Wed, 13 Nov 2024 06:21:31 +0900 Subject: [PATCH] use function in config for emojiSet to keep Config being const and update Readme --- README.md | 13 +++++++++++-- lib/src/config.dart | 5 +++-- lib/src/emoji_picker.dart | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a911a7..3d25902 100644 --- a/README.md +++ b/README.md @@ -236,11 +236,11 @@ Config( locale: const Locale("ja"), ) ``` -In case you want to support additional languages, you need to create a copy of a emoji set file (see /lib/locales), transalte it and adjust the config for `emojiSet`: +In case you want to support additional languages, you need to create a copy of a emoji set file (see /lib/locales), translate it (optional use `/automation/create_emoji_set.sh` to help you) and adjust the config for `emojiSet`: ```dart EmojiPicker( config: Config( - emojiSet: _getEmojiLocale(locale), + emojiSet: _getEmojiLocale, ), ) @@ -257,6 +257,15 @@ List _getEmojiLocale(String locale) { ``` Feel free to create an issue if you think a specific language should be supported by default. We keep the languages limited for now to avoid the package size growing unnecesserily large. +In case you want to support only a single language you can just return the same EmojiSet for all locales. +``` +List _getEmojiLocale(String locale) { + return emojiSetEnglish; +} +``` +Using a single EmojiSet will reduce the package size by about 2 MB. +If you prefer to use the old EmojiSet (version 3 and below), you can return `defaultEmojiSet`. + ## Extended usage with EmojiPickerUtils Find usage example [here](https://github.com/Fintasys/emoji_picker_flutter/blob/master/example/lib/main_key.dart) diff --git a/lib/src/config.dart b/lib/src/config.dart index f945498..9f0cb67 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -1,4 +1,5 @@ import 'package:emoji_picker_flutter/emoji_picker_flutter.dart'; +import 'package:emoji_picker_flutter/locales/default_emoji_set_locale.dart'; import 'package:flutter/material.dart'; /// Number of skin tone icons @@ -10,7 +11,7 @@ class Config { const Config({ this.height = 256, this.checkPlatformCompatibility = true, - this.emojiSet, + this.emojiSet = getDefaultEmojiLocale, this.locale = const Locale('en'), this.emojiTextStyle, this.customBackspaceIcon, @@ -34,7 +35,7 @@ class Config { /// default_emoji_set_locale.dart). /// If not provided, the default emoji set will be used based on the /// locales that are available in the package. - final List? emojiSet; + final List Function(Locale locale)? emojiSet; /// Locale to choose the fitting language for the emoji set /// This will affect the emoji search results diff --git a/lib/src/emoji_picker.dart b/lib/src/emoji_picker.dart index 24a95e8..2eeda55 100644 --- a/lib/src/emoji_picker.dart +++ b/lib/src/emoji_picker.dart @@ -366,8 +366,8 @@ class EmojiPickerState extends State { final recentEmojiMap = _recentEmoji.map((e) => e.emoji).toList(); _categoryEmoji.add(CategoryEmoji(Category.RECENT, recentEmojiMap)); } - final data = - widget.config.emojiSet ?? getDefaultEmojiLocale(widget.config.locale); + final data = widget.config.emojiSet?.call(widget.config.locale) ?? + getDefaultEmojiLocale(widget.config.locale); _categoryEmoji.addAll(widget.config.checkPlatformCompatibility ? await _emojiPickerInternalUtils.filterUnsupported(data) : data);