refactor: Use localized emojis for suggestion input
This commit is contained in:
parent
6560f7e533
commit
e7f9302e52
4 changed files with 36 additions and 27 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:animations/animations.dart';
|
||||
import 'package:emoji_picker_flutter/locales/default_emoji_set_locale.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
|
|
@ -334,6 +335,12 @@ class ChatInputRow extends StatelessWidget {
|
|||
filled: false,
|
||||
),
|
||||
onChanged: controller.onInputBarChanged,
|
||||
suggestionEmojis: getDefaultEmojiLocale(
|
||||
Localizations.localeOf(context),
|
||||
).fold(
|
||||
[],
|
||||
(emojis, category) => emojis..addAll(category.emoji),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:emojis/emoji.dart';
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:slugify/slugify.dart';
|
||||
|
||||
|
|
@ -28,6 +28,7 @@ class InputBar extends StatelessWidget {
|
|||
final ValueChanged<String>? onChanged;
|
||||
final bool? autofocus;
|
||||
final bool readOnly;
|
||||
final List<Emoji> suggestionEmojis;
|
||||
|
||||
const InputBar({
|
||||
required this.room,
|
||||
|
|
@ -43,6 +44,7 @@ class InputBar extends StatelessWidget {
|
|||
this.autofocus,
|
||||
this.textInputAction,
|
||||
this.readOnly = false,
|
||||
required this.suggestionEmojis,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
|
@ -115,13 +117,12 @@ class InputBar extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// aside of emote packs, also propose normal (tm) unicode emojis
|
||||
final matchingUnicodeEmojis = Emoji.all()
|
||||
.where(
|
||||
(element) => [element.name, ...element.keywords]
|
||||
.any((element) => element.toLowerCase().contains(emoteSearch)),
|
||||
)
|
||||
final matchingUnicodeEmojis = suggestionEmojis
|
||||
.where((emoji) => emoji.name.toLowerCase().contains(emoteSearch))
|
||||
.toList();
|
||||
|
||||
// sort by the index of the search term in the name in order to have
|
||||
// best matches first
|
||||
// (thanks for the hint by github.com/nextcloud/circles devs)
|
||||
|
|
@ -141,9 +142,8 @@ class InputBar extends StatelessWidget {
|
|||
for (final emoji in matchingUnicodeEmojis) {
|
||||
ret.add({
|
||||
'type': 'emoji',
|
||||
'emoji': emoji.char,
|
||||
// don't include sub-group names, splitting at `:` hence
|
||||
'label': '${emoji.char} - ${emoji.name.split(':').first}',
|
||||
'emoji': emoji.emoji,
|
||||
'label': emoji.name,
|
||||
'current_word': ':$emoteSearch',
|
||||
});
|
||||
if (ret.length > maxResults) {
|
||||
|
|
@ -249,7 +249,18 @@ class InputBar extends StatelessWidget {
|
|||
waitDuration: const Duration(days: 1), // don't show on hover
|
||||
child: ListTile(
|
||||
onTap: () => onSelected(suggestion),
|
||||
title: Text(label, style: const TextStyle(fontFamily: 'RobotoMono')),
|
||||
leading: SizedBox.square(
|
||||
dimension: size,
|
||||
child: Text(
|
||||
suggestion['emoji']!,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
24
pubspec.lock
24
pubspec.lock
|
|
@ -361,14 +361,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.3.0"
|
||||
emojis:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: emojis
|
||||
sha256: "2e4d847c3f1e2670f30dc355909ce6fa7808b4e626c34a4dd503a360995a38bf"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.9"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1112,10 +1104,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
||||
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.17.0"
|
||||
version: "1.16.0"
|
||||
mgrs_dart:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -1837,26 +1829,26 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: test
|
||||
sha256: "75906bf273541b676716d1ca7627a17e4c4070a3a16272b7a3dc7da3b9f3f6b7"
|
||||
sha256: "65e29d831719be0591f7b3b1a32a3cda258ec98c58c7b25f7b84241bc31215bb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.26.3"
|
||||
version: "1.26.2"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
|
||||
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.7"
|
||||
version: "0.7.6"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
sha256: "0cc24b5ff94b38d2ae73e1eb43cc302b77964fbf67abad1e296025b78deb53d0"
|
||||
sha256: "80bf5a02b60af04b09e14f6fe68b921aad119493e26e490deaca5993fef1b05a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.12"
|
||||
version: "0.6.11"
|
||||
timezone:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ dependencies:
|
|||
device_info_plus: ^12.2.0
|
||||
dynamic_color: ^1.8.1
|
||||
emoji_picker_flutter: ^4.3.0
|
||||
emojis: ^0.9.9
|
||||
file_picker: ^10.3.6
|
||||
file_selector: ^1.0.4
|
||||
flutter:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue