You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
7.6 KiB
172 lines
7.6 KiB
import 'package:get_storage/get_storage.dart';
|
|
|
|
/// 表情配置
|
|
class EmojiItem {
|
|
final String id;
|
|
final String name;
|
|
final String path;
|
|
|
|
const EmojiItem({
|
|
required this.id,
|
|
required this.name,
|
|
required this.path,
|
|
});
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'name': name,
|
|
'path': path,
|
|
};
|
|
|
|
factory EmojiItem.fromJson(Map<String, dynamic> json) => EmojiItem(
|
|
id: json['id'],
|
|
name: json['name'],
|
|
path: json['path'],
|
|
);
|
|
}
|
|
|
|
class EmojiConfig {
|
|
static const String basePath = 'assets/images/emoji/';
|
|
|
|
/// 所有表情列表(笑脸表情已排到前面)
|
|
static const List<EmojiItem> allEmojis = [
|
|
// 笑脸表情放在最前面
|
|
EmojiItem(id: '19', name: '开心', path: '${basePath}emoji_19.png'),
|
|
EmojiItem(id: '06', name: '吐舌笑', path: '${basePath}emoji_06.png'),
|
|
EmojiItem(id: '11', name: '墨镜笑', path: '${basePath}emoji_11.png'),
|
|
EmojiItem(id: '14', name: '奸笑', path: '${basePath}emoji_14.png'),
|
|
EmojiItem(id: '17', name: '尴尬笑', path: '${basePath}emoji_17.png'),
|
|
EmojiItem(id: '47', name: '猫咪笑', path: '${basePath}emoji_47.png'),
|
|
EmojiItem(id: '54', name: '笑哭', path: '${basePath}emoji_54.png'),
|
|
// 其他表情
|
|
EmojiItem(id: '01', name: '不爽', path: '${basePath}emoji_01.png'),
|
|
EmojiItem(id: '02', name: '不自在', path: '${basePath}emoji_02.png'),
|
|
EmojiItem(id: '03', name: '兴奋', path: '${basePath}emoji_03.png'),
|
|
EmojiItem(id: '04', name: '叹气', path: '${basePath}emoji_04.png'),
|
|
EmojiItem(id: '05', name: '吃惊', path: '${basePath}emoji_05.png'),
|
|
EmojiItem(id: '07', name: '吐舌头', path: '${basePath}emoji_07.png'),
|
|
EmojiItem(id: '08', name: '哭泣', path: '${basePath}emoji_08.png'),
|
|
EmojiItem(id: '09', name: '困了', path: '${basePath}emoji_09.png'),
|
|
EmojiItem(id: '10', name: '困惑', path: '${basePath}emoji_10.png'),
|
|
EmojiItem(id: '12', name: '大哭', path: '${basePath}emoji_12.png'),
|
|
EmojiItem(id: '13', name: '失望', path: '${basePath}emoji_13.png'),
|
|
EmojiItem(id: '15', name: '害羞', path: '${basePath}emoji_15.png'),
|
|
EmojiItem(id: '16', name: '尴尬', path: '${basePath}emoji_16.png'),
|
|
EmojiItem(id: '18', name: '尴尬露齿', path: '${basePath}emoji_18.png'),
|
|
EmojiItem(id: '20', name: '恶心', path: '${basePath}emoji_20.png'),
|
|
EmojiItem(id: '21', name: '惊恐', path: '${basePath}emoji_21.png'),
|
|
EmojiItem(id: '22', name: '惊讶', path: '${basePath}emoji_22.png'),
|
|
EmojiItem(id: '23', name: '惊讶张嘴', path: '${basePath}emoji_23.png'),
|
|
EmojiItem(id: '24', name: '惊讶感叹', path: '${basePath}emoji_24.png'),
|
|
EmojiItem(id: '25', name: '愤怒咬牙', path: '${basePath}emoji_25.png'),
|
|
EmojiItem(id: '26', name: '愤怒大叫', path: '${basePath}emoji_26.png'),
|
|
EmojiItem(id: '27', name: '戴口罩', path: '${basePath}emoji_27.png'),
|
|
EmojiItem(id: '28', name: '戴墨镜', path: '${basePath}emoji_28.png'),
|
|
EmojiItem(id: '29', name: '抿嘴', path: '${basePath}emoji_29.png'),
|
|
EmojiItem(id: '30', name: '担忧', path: '${basePath}emoji_30.png'),
|
|
EmojiItem(id: '31', name: '斜眼不满', path: '${basePath}emoji_31.png'),
|
|
EmojiItem(id: '32', name: '斜眼尴尬', path: '${basePath}emoji_32.png'),
|
|
EmojiItem(id: '33', name: '斜眼无语', path: '${basePath}emoji_33.png'),
|
|
EmojiItem(id: '34', name: '斜眼看', path: '${basePath}emoji_34.png'),
|
|
EmojiItem(id: '35', name: '斜眼迟疑', path: '${basePath}emoji_35.png'),
|
|
EmojiItem(id: '36', name: '无聊', path: '${basePath}emoji_36.png'),
|
|
EmojiItem(id: '37', name: '无语', path: '${basePath}emoji_37.png'),
|
|
EmojiItem(id: '38', name: '星星眼', path: '${basePath}emoji_38.png'),
|
|
EmojiItem(id: '39', name: '晕倒', path: '${basePath}emoji_39.png'),
|
|
EmojiItem(id: '40', name: '晕眩', path: '${basePath}emoji_40.png'),
|
|
EmojiItem(id: '41', name: '流口水', path: '${basePath}emoji_41.png'),
|
|
EmojiItem(id: '42', name: '流泪', path: '${basePath}emoji_42.png'),
|
|
EmojiItem(id: '43', name: '流鼻涕', path: '${basePath}emoji_43.png'),
|
|
EmojiItem(id: '44', name: '火冒三丈', path: '${basePath}emoji_44.png'),
|
|
EmojiItem(id: '45', name: '焦虑', path: '${basePath}emoji_45.png'),
|
|
EmojiItem(id: '46', name: '狡猾', path: '${basePath}emoji_46.png'),
|
|
EmojiItem(id: '48', name: '生气', path: '${basePath}emoji_48.png'),
|
|
EmojiItem(id: '49', name: '生气皱眉', path: '${basePath}emoji_49.png'),
|
|
EmojiItem(id: '50', name: '疑问', path: '${basePath}emoji_50.png'),
|
|
EmojiItem(id: '51', name: '眨眼害羞', path: '${basePath}emoji_51.png'),
|
|
EmojiItem(id: '52', name: '眨眼飞吻', path: '${basePath}emoji_52.png'),
|
|
EmojiItem(id: '53', name: '禁言', path: '${basePath}emoji_53.png'),
|
|
EmojiItem(id: '55', name: '翻白眼', path: '${basePath}emoji_55.png'),
|
|
EmojiItem(id: '56', name: '翻白眼叹气', path: '${basePath}emoji_56.png'),
|
|
EmojiItem(id: '57', name: '翻白眼无奈', path: '${basePath}emoji_57.png'),
|
|
EmojiItem(id: '58', name: '花痴', path: '${basePath}emoji_58.png'),
|
|
EmojiItem(id: '59', name: '见钱眼开', path: '${basePath}emoji_59.png'),
|
|
EmojiItem(id: '60', name: '闭嘴', path: '${basePath}emoji_60.png'),
|
|
EmojiItem(id: '61', name: '震惊大叫', path: '${basePath}emoji_61.png'),
|
|
EmojiItem(id: '62', name: '震惊无语', path: '${basePath}emoji_62.png'),
|
|
EmojiItem(id: '63', name: '面无表情', path: '${basePath}emoji_63.png'),
|
|
EmojiItem(id: '64', name: '飞吻', path: '${basePath}emoji_64.png'),
|
|
];
|
|
|
|
/// 根据ID获取表情
|
|
static EmojiItem? getEmojiById(String id) {
|
|
try {
|
|
return allEmojis.firstWhere((emoji) => emoji.id == id);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// 根据名称获取表情
|
|
static EmojiItem? getEmojiByName(String name) {
|
|
try {
|
|
return allEmojis.firstWhere((emoji) => emoji.name == name);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// 获取所有表情ID列表
|
|
static List<String> get allEmojiIds => allEmojis.map((e) => e.id).toList();
|
|
|
|
/// 获取所有表情名称列表
|
|
static List<String> get allEmojiNames => allEmojis.map((e) => e.name).toList();
|
|
|
|
// ==================== 最近使用管理 ====================
|
|
static const String _recentEmojisKey = 'recent_emojis';
|
|
static const int _maxRecentCount = 24; // 最多保存24个最近使用的表情
|
|
|
|
/// 获取最近使用的表情列表
|
|
static List<EmojiItem> getRecentEmojis() {
|
|
final storage = GetStorage();
|
|
final List<dynamic>? recentList = storage.read(_recentEmojisKey);
|
|
if (recentList == null || recentList.isEmpty) {
|
|
return [];
|
|
}
|
|
return recentList
|
|
.map((json) => EmojiItem.fromJson(Map<String, dynamic>.from(json)))
|
|
.toList();
|
|
}
|
|
|
|
/// 添加到最近使用(去重并置顶)
|
|
static void addToRecentEmojis(EmojiItem emoji) {
|
|
final storage = GetStorage();
|
|
List<EmojiItem> recentEmojis = getRecentEmojis();
|
|
|
|
// 移除已存在的相同表情
|
|
recentEmojis.removeWhere((item) => item.id == emoji.id);
|
|
|
|
// 添加到列表开头
|
|
recentEmojis.insert(0, emoji);
|
|
|
|
// 限制最大数量
|
|
if (recentEmojis.length > _maxRecentCount) {
|
|
recentEmojis = recentEmojis.sublist(0, _maxRecentCount);
|
|
}
|
|
|
|
// 保存
|
|
storage.write(_recentEmojisKey, recentEmojis.map((e) => e.toJson()).toList());
|
|
}
|
|
|
|
/// 清空最近使用
|
|
static void clearRecentEmojis() {
|
|
final storage = GetStorage();
|
|
storage.remove(_recentEmojisKey);
|
|
}
|
|
|
|
/// 是否有最近使用的表情
|
|
static bool hasRecentEmojis() {
|
|
return getRecentEmojis().isNotEmpty;
|
|
}
|
|
}
|
|
|