Skip to content

Commit

Permalink
use function in config for emojiSet to keep Config being const and up…
Browse files Browse the repository at this point in the history
…date Readme
  • Loading branch information
Fintasys committed Nov 12, 2024
1 parent 90f6ef5 commit eb5e97f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)
Expand All @@ -257,6 +257,15 @@ List<CategoryEmoji> _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<CategoryEmoji> _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)
Expand Down
5 changes: 3 additions & 2 deletions lib/src/config.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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<CategoryEmoji>? emojiSet;
final List<CategoryEmoji> Function(Locale locale)? emojiSet;

/// Locale to choose the fitting language for the emoji set
/// This will affect the emoji search results
Expand Down
4 changes: 2 additions & 2 deletions lib/src/emoji_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ class EmojiPickerState extends State<EmojiPicker> {
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);
Expand Down

0 comments on commit eb5e97f

Please sign in to comment.