2025-02-06 15:04:04 +08:00
|
|
|
import 'dart:io';
|
2025-02-04 02:33:19 +08:00
|
|
|
import 'dart:math' show min;
|
|
|
|
|
2024-11-17 21:30:02 +08:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:flutter/foundation.dart';
|
2024-11-17 01:16:54 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2024-11-17 01:16:54 +08:00
|
|
|
import 'package:gap/gap.dart';
|
2025-02-04 02:33:19 +08:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:hotkey_manager/hotkey_manager.dart';
|
2024-11-17 01:16:54 +08:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2025-02-06 15:04:04 +08:00
|
|
|
import 'package:pasteboard/pasteboard.dart';
|
2024-11-18 00:55:39 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2024-11-17 01:16:54 +08:00
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
import 'package:surface/controllers/chat_message_controller.dart';
|
2024-11-18 00:55:39 +08:00
|
|
|
import 'package:surface/controllers/post_write_controller.dart';
|
|
|
|
import 'package:surface/providers/sn_attachment.dart';
|
2025-02-04 02:33:19 +08:00
|
|
|
import 'package:surface/providers/sn_network.dart';
|
|
|
|
import 'package:surface/providers/sn_sticker.dart';
|
2024-12-14 01:32:13 +08:00
|
|
|
import 'package:surface/providers/user_directory.dart';
|
2024-12-26 22:19:01 +08:00
|
|
|
import 'package:surface/types/attachment.dart';
|
2024-11-18 22:33:03 +08:00
|
|
|
import 'package:surface/types/chat.dart';
|
2024-11-18 00:55:39 +08:00
|
|
|
import 'package:surface/widgets/dialog.dart';
|
|
|
|
import 'package:surface/widgets/post/post_media_pending_list.dart';
|
2025-02-04 02:33:19 +08:00
|
|
|
import 'package:surface/widgets/universal_image.dart';
|
2024-11-17 01:16:54 +08:00
|
|
|
|
|
|
|
class ChatMessageInput extends StatefulWidget {
|
|
|
|
final ChatMessageController controller;
|
2024-12-08 13:45:51 +08:00
|
|
|
final SnChannelMember? otherMember;
|
2024-12-07 23:40:26 +08:00
|
|
|
|
2024-12-08 13:45:51 +08:00
|
|
|
const ChatMessageInput({super.key, required this.controller, this.otherMember});
|
2024-11-17 01:16:54 +08:00
|
|
|
|
|
|
|
@override
|
2024-11-18 22:33:03 +08:00
|
|
|
State<ChatMessageInput> createState() => ChatMessageInputState();
|
2024-11-17 01:16:54 +08:00
|
|
|
}
|
|
|
|
|
2024-11-18 22:33:03 +08:00
|
|
|
class ChatMessageInputState extends State<ChatMessageInput> {
|
2024-11-18 00:55:39 +08:00
|
|
|
bool _isBusy = false;
|
|
|
|
double? _progress;
|
|
|
|
|
2024-11-18 23:59:08 +08:00
|
|
|
SnChatMessage? _replyingMessage, _editingMessage;
|
2024-11-18 22:33:03 +08:00
|
|
|
|
2024-11-17 01:16:54 +08:00
|
|
|
final TextEditingController _contentController = TextEditingController();
|
|
|
|
final FocusNode _focusNode = FocusNode();
|
|
|
|
|
2025-02-06 15:04:04 +08:00
|
|
|
final HotKey _pasteHotKey = HotKey(
|
|
|
|
key: PhysicalKeyboardKey.keyV,
|
2025-02-15 13:06:25 +08:00
|
|
|
modifiers: [(!kIsWeb && Platform.isMacOS) ? HotKeyModifier.meta : HotKeyModifier.control],
|
2025-02-06 15:04:04 +08:00
|
|
|
scope: HotKeyScope.inapp,
|
|
|
|
);
|
2025-02-15 19:08:40 +08:00
|
|
|
final HotKey _newLineHotKey = HotKey(
|
|
|
|
key: PhysicalKeyboardKey.enter,
|
|
|
|
modifiers: [(!kIsWeb && Platform.isMacOS) ? HotKeyModifier.meta : HotKeyModifier.control],
|
|
|
|
scope: HotKeyScope.inapp,
|
|
|
|
);
|
2025-02-06 15:04:04 +08:00
|
|
|
|
|
|
|
void _registerHotKey() {
|
|
|
|
if (kIsWeb || Platform.isAndroid || Platform.isIOS) return;
|
|
|
|
hotKeyManager.register(_pasteHotKey, keyDownHandler: (_) async {
|
|
|
|
final imageBytes = await Pasteboard.image;
|
|
|
|
if (imageBytes == null) return;
|
|
|
|
_attachments.add(PostWriteMedia.fromBytes(
|
|
|
|
imageBytes,
|
|
|
|
'attachmentPastedImage'.tr(),
|
|
|
|
SnMediaType.image,
|
|
|
|
));
|
|
|
|
setState(() {});
|
|
|
|
});
|
2025-02-15 19:08:40 +08:00
|
|
|
hotKeyManager.register(_newLineHotKey, keyDownHandler: (_) async {
|
|
|
|
if (_contentController.text.isEmpty) return;
|
|
|
|
_contentController.text += '\n';
|
|
|
|
});
|
2025-02-06 15:04:04 +08:00
|
|
|
}
|
|
|
|
|
2025-01-01 16:45:37 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2025-02-06 15:04:04 +08:00
|
|
|
_registerHotKey();
|
2025-01-01 16:45:37 +08:00
|
|
|
_contentController.addListener(() {
|
|
|
|
if (_contentController.text.isNotEmpty) {
|
|
|
|
widget.controller.pingTypingStatus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-18 22:33:03 +08:00
|
|
|
void setReply(SnChatMessage? value) {
|
|
|
|
setState(() => _replyingMessage = value);
|
|
|
|
}
|
|
|
|
|
2025-01-31 22:52:21 +08:00
|
|
|
void setInitialText(String? value) {
|
|
|
|
_contentController.text = value ?? '';
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInitialAttachments(List<PostWriteMedia>? value) {
|
|
|
|
_attachments.addAll(value ?? []);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2024-11-18 23:59:08 +08:00
|
|
|
void setEdit(SnChatMessage? value) {
|
2024-11-25 00:05:49 +08:00
|
|
|
_contentController.text = value?.body['text'] ?? '';
|
2025-01-08 17:48:46 +08:00
|
|
|
_attachments.clear();
|
|
|
|
_attachments.addAll(value?.preload?.attachments?.map((e) => PostWriteMedia(e)) ?? []);
|
2024-11-18 23:59:08 +08:00
|
|
|
setState(() => _editingMessage = value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> deleteMessage(SnChatMessage message) async {
|
|
|
|
final confirm = await context.showConfirmDialog(
|
|
|
|
'messageDelete'.tr(args: ['#${message.id}']),
|
|
|
|
'messageDeleteDescription'.tr(),
|
|
|
|
);
|
|
|
|
if (!confirm) return;
|
|
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
|
|
|
|
await widget.controller.deleteMessage(message);
|
|
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
|
2024-11-18 00:55:39 +08:00
|
|
|
Future<void> _sendMessage() async {
|
2025-02-15 18:12:35 +08:00
|
|
|
if (_contentController.text.isEmpty && _attachments.isEmpty) return;
|
2024-11-18 00:55:39 +08:00
|
|
|
if (_isBusy) return;
|
|
|
|
|
|
|
|
final attach = context.read<SnAttachmentProvider>();
|
|
|
|
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < _attachments.length; i++) {
|
|
|
|
final media = _attachments[i];
|
|
|
|
if (media.attachment != null) continue; // Already uploaded, skip
|
|
|
|
if (media.isEmpty) continue; // Nothing to do, skip
|
|
|
|
|
|
|
|
final place = await attach.chunkedUploadInitialize(
|
|
|
|
(await media.length())!,
|
|
|
|
media.name,
|
2024-12-10 21:45:27 +08:00
|
|
|
'messaging',
|
2024-11-18 00:55:39 +08:00
|
|
|
null,
|
2024-12-26 22:19:01 +08:00
|
|
|
mimetype: media.raw != null && media.type == SnMediaType.image ? 'image/png' : null,
|
2024-11-18 00:55:39 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
final item = await attach.chunkedUploadParts(
|
|
|
|
media.toFile()!,
|
|
|
|
place.$1,
|
|
|
|
place.$2,
|
2024-12-29 11:09:54 +08:00
|
|
|
analyzeNow: media.type == SnMediaType.image,
|
2024-11-18 00:55:39 +08:00
|
|
|
onProgress: (progress) {
|
|
|
|
// Calculate overall progress for attachments
|
|
|
|
setState(() {
|
|
|
|
progress = (i + progress) / _attachments.length;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2025-01-08 17:37:16 +08:00
|
|
|
setState(() {
|
|
|
|
_attachments[i] = PostWriteMedia(item);
|
|
|
|
});
|
2024-11-18 00:55:39 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
if (!mounted) return;
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
context.showErrorDialog(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the message
|
|
|
|
// NOTICE This future should not be awaited, so that the message can be sent in the background and the user can continue to type
|
2024-11-17 01:16:54 +08:00
|
|
|
widget.controller.sendMessage(
|
2025-01-15 15:14:13 +08:00
|
|
|
_editingMessage != null ? 'messages.edit' : 'messages.new',
|
2024-11-17 01:16:54 +08:00
|
|
|
_contentController.text,
|
2024-12-07 23:40:26 +08:00
|
|
|
attachments: _attachments.where((e) => e.attachment != null).map((e) => e.attachment!.rid).toList(),
|
2024-11-18 23:59:08 +08:00
|
|
|
relatedId: _editingMessage?.id,
|
2024-11-18 22:33:03 +08:00
|
|
|
quoteId: _replyingMessage?.id,
|
2024-11-18 23:59:08 +08:00
|
|
|
editingMessage: _editingMessage,
|
2024-11-17 01:16:54 +08:00
|
|
|
);
|
|
|
|
_contentController.clear();
|
2024-11-18 00:55:39 +08:00
|
|
|
_attachments.clear();
|
2024-11-18 23:59:08 +08:00
|
|
|
_editingMessage = null;
|
2024-11-18 22:33:03 +08:00
|
|
|
_replyingMessage = null;
|
2024-11-18 00:55:39 +08:00
|
|
|
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
final List<PostWriteMedia> _attachments = List.empty(growable: true);
|
2024-11-22 00:28:29 +08:00
|
|
|
|
2025-02-04 02:33:19 +08:00
|
|
|
OverlayEntry? _overlayEntry;
|
|
|
|
|
|
|
|
void _showEmojiPicker(BuildContext context) {
|
|
|
|
final overlay = Overlay.of(context);
|
|
|
|
_overlayEntry = OverlayEntry(
|
|
|
|
builder: (context) => Positioned(
|
|
|
|
bottom: 16 + MediaQuery.of(context).padding.bottom,
|
|
|
|
right: 16,
|
|
|
|
child: _StickerPicker(
|
|
|
|
originalText: _contentController.text,
|
|
|
|
onDismiss: () => _dismissEmojiPicker(),
|
|
|
|
onInsert: (str) => _contentController.text = str,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
overlay.insert(_overlayEntry!);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _dismissEmojiPicker() {
|
|
|
|
_overlayEntry?.remove();
|
|
|
|
}
|
|
|
|
|
2024-11-17 01:16:54 +08:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_contentController.dispose();
|
|
|
|
_focusNode.dispose();
|
2025-02-10 18:00:15 +08:00
|
|
|
_dismissEmojiPicker();
|
2025-02-15 19:08:40 +08:00
|
|
|
if (!kIsWeb && !(Platform.isAndroid || Platform.isIOS)) {
|
|
|
|
hotKeyManager.unregister(_pasteHotKey);
|
|
|
|
hotKeyManager.unregister(_newLineHotKey);
|
|
|
|
}
|
2024-11-17 01:16:54 +08:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-12-08 13:45:51 +08:00
|
|
|
final ud = context.read<UserDirectoryProvider>();
|
|
|
|
|
2024-11-17 21:30:02 +08:00
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2024-11-18 00:55:39 +08:00
|
|
|
if (_isBusy && _progress != null)
|
|
|
|
TweenAnimationBuilder<double>(
|
|
|
|
tween: Tween(begin: 0, end: _progress),
|
|
|
|
duration: Duration(milliseconds: 300),
|
2024-12-07 23:40:26 +08:00
|
|
|
builder: (context, value, _) => LinearProgressIndicator(value: value, minHeight: 2),
|
2024-11-18 00:55:39 +08:00
|
|
|
)
|
|
|
|
else if (_isBusy)
|
|
|
|
const LinearProgressIndicator(value: null, minHeight: 2),
|
|
|
|
Padding(
|
2024-12-07 23:40:26 +08:00
|
|
|
padding: _attachments.isNotEmpty ? const EdgeInsets.only(top: 8) : EdgeInsets.zero,
|
2024-11-23 17:32:48 +08:00
|
|
|
child: PostMediaPendingList(
|
2024-11-18 00:55:39 +08:00
|
|
|
attachments: _attachments,
|
|
|
|
isBusy: _isBusy,
|
|
|
|
onUpdate: (idx, updatedMedia) async {
|
|
|
|
setState(() => _attachments[idx] = updatedMedia);
|
|
|
|
},
|
|
|
|
onRemove: (idx) async {
|
|
|
|
setState(() => _attachments.removeAt(idx));
|
|
|
|
},
|
|
|
|
onUpdateBusy: (state) => setState(() => _isBusy = state),
|
2024-11-18 22:33:03 +08:00
|
|
|
),
|
2024-12-07 23:40:26 +08:00
|
|
|
)
|
|
|
|
.height(_attachments.isNotEmpty ? 80 + 8 : 0, animate: true)
|
|
|
|
.animate(const Duration(milliseconds: 300), Curves.fastEaseInToSlowEaseOut),
|
2024-11-18 22:33:03 +08:00
|
|
|
SingleChildScrollView(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
2024-12-29 23:30:29 +08:00
|
|
|
child: _replyingMessage != null
|
|
|
|
? Container(
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
width: 1 / MediaQuery.of(context).devicePixelRatio,
|
2024-11-18 22:33:03 +08:00
|
|
|
),
|
|
|
|
),
|
2024-12-29 23:30:29 +08:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Symbols.reply, size: 20),
|
|
|
|
const Gap(8),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
_replyingMessage?.body['text'] ?? '${_replyingMessage?.sender.nick}',
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Gap(16),
|
|
|
|
InkWell(
|
2024-11-18 22:33:03 +08:00
|
|
|
child: Text('cancel'.tr()),
|
2024-12-29 23:30:29 +08:00
|
|
|
onTap: () {
|
2025-01-08 17:48:46 +08:00
|
|
|
_attachments.clear();
|
2024-11-18 22:33:03 +08:00
|
|
|
setState(() => _replyingMessage = null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2024-12-29 23:30:29 +08:00
|
|
|
).padding(vertical: 8),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink(),
|
2024-12-07 23:40:26 +08:00
|
|
|
)
|
2024-12-29 23:30:29 +08:00
|
|
|
.height(_replyingMessage != null ? 38 : 0, animate: true)
|
2024-12-07 23:40:26 +08:00
|
|
|
.animate(const Duration(milliseconds: 300), Curves.fastEaseInToSlowEaseOut),
|
2024-11-18 23:59:08 +08:00
|
|
|
SingleChildScrollView(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
2024-12-29 23:30:29 +08:00
|
|
|
child: _editingMessage != null
|
|
|
|
? Container(
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 16),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
width: 1 / MediaQuery.of(context).devicePixelRatio,
|
2024-11-18 23:59:08 +08:00
|
|
|
),
|
|
|
|
),
|
2024-12-29 23:30:29 +08:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(Symbols.edit, size: 20),
|
|
|
|
const Gap(8),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
_editingMessage?.body['text'] ?? '${_editingMessage?.sender.nick}',
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Gap(16),
|
|
|
|
InkWell(
|
2024-11-18 23:59:08 +08:00
|
|
|
child: Text('cancel'.tr()),
|
2024-12-29 23:30:29 +08:00
|
|
|
onTap: () {
|
2025-01-08 17:48:46 +08:00
|
|
|
_attachments.clear();
|
2024-12-29 23:30:29 +08:00
|
|
|
_contentController.clear();
|
2024-11-18 23:59:08 +08:00
|
|
|
setState(() => _editingMessage = null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2024-12-29 23:30:29 +08:00
|
|
|
).padding(vertical: 8),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink(),
|
2024-12-07 23:40:26 +08:00
|
|
|
)
|
2024-12-29 23:30:29 +08:00
|
|
|
.height(_editingMessage != null ? 38 : 0, animate: true)
|
2024-12-07 23:40:26 +08:00
|
|
|
.animate(const Duration(milliseconds: 300), Curves.fastEaseInToSlowEaseOut),
|
2024-11-17 21:30:02 +08:00
|
|
|
SizedBox(
|
|
|
|
height: 56,
|
|
|
|
child: Row(
|
2024-11-17 01:16:54 +08:00
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
focusNode: _focusNode,
|
|
|
|
controller: _contentController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
isCollapsed: true,
|
2024-12-08 13:45:51 +08:00
|
|
|
hintText: widget.otherMember != null
|
|
|
|
? 'fieldChatMessageDirect'.tr(args: [
|
|
|
|
'@${ud.getAccountFromCache(widget.otherMember?.accountId)?.name}',
|
|
|
|
])
|
|
|
|
: 'fieldChatMessage'.tr(args: [widget.controller.channel?.name ?? 'loading'.tr()]),
|
2024-11-17 01:16:54 +08:00
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
2025-02-07 22:35:04 +08:00
|
|
|
textInputAction: TextInputAction.send,
|
2024-12-07 23:40:26 +08:00
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
2024-11-17 01:16:54 +08:00
|
|
|
onSubmitted: (_) {
|
2024-11-18 00:55:39 +08:00
|
|
|
if (_isBusy) return;
|
2024-11-17 01:16:54 +08:00
|
|
|
_sendMessage();
|
|
|
|
_focusNode.requestFocus();
|
|
|
|
},
|
2025-02-15 19:08:40 +08:00
|
|
|
maxLines: null,
|
2024-11-17 01:16:54 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const Gap(8),
|
2025-02-04 02:33:19 +08:00
|
|
|
IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Symbols.mood,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
2025-02-12 23:56:45 +08:00
|
|
|
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
constraints: const BoxConstraints(),
|
2025-02-04 02:33:19 +08:00
|
|
|
onPressed: () {
|
|
|
|
_showEmojiPicker(context);
|
|
|
|
},
|
|
|
|
),
|
2024-12-25 00:48:19 +08:00
|
|
|
AddPostMediaButton(
|
|
|
|
onAdd: (items) {
|
|
|
|
setState(() {
|
|
|
|
_attachments.addAll(items);
|
|
|
|
});
|
|
|
|
},
|
2024-11-18 00:55:39 +08:00
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: _isBusy ? null : _sendMessage,
|
2024-11-17 01:16:54 +08:00
|
|
|
icon: Icon(
|
|
|
|
Symbols.send,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
2025-02-12 23:56:45 +08:00
|
|
|
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
constraints: const BoxConstraints(),
|
2024-11-17 01:16:54 +08:00
|
|
|
),
|
|
|
|
],
|
2024-11-17 21:30:02 +08:00
|
|
|
),
|
|
|
|
).padding(horizontal: 16),
|
|
|
|
],
|
2024-11-17 01:16:54 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2025-02-04 02:33:19 +08:00
|
|
|
|
|
|
|
class _StickerPicker extends StatelessWidget {
|
|
|
|
final String originalText;
|
|
|
|
final Function? onDismiss;
|
|
|
|
final Function(String)? onInsert;
|
|
|
|
|
2025-02-04 15:43:20 +08:00
|
|
|
const _StickerPicker({this.onDismiss, required this.originalText, this.onInsert});
|
2025-02-04 02:33:19 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final sticker = context.read<SnStickerProvider>();
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
onDismiss?.call();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
constraints: BoxConstraints(maxWidth: min(360, MediaQuery.of(context).size.width), maxHeight: 240),
|
|
|
|
child: Material(
|
|
|
|
elevation: 8,
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: ListView(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
children: sticker.stickersByPack.entries
|
|
|
|
.map((e) {
|
|
|
|
return <Widget>[
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.only(bottom: 8),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(e.value.first.pack.name).bold(),
|
|
|
|
Text(e.value.first.pack.description),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
GridView.builder(
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
|
|
|
|
shrinkWrap: true,
|
|
|
|
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: 48,
|
|
|
|
childAspectRatio: 1.0,
|
|
|
|
mainAxisSpacing: 8,
|
|
|
|
crossAxisSpacing: 8,
|
|
|
|
),
|
|
|
|
itemCount: e.value.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
|
|
|
final element = e.value[index];
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
final withSpace = originalText.isNotEmpty;
|
|
|
|
onInsert?.call(
|
|
|
|
'$originalText${withSpace ? ' ' : ''}:${element.pack.prefix}${element.alias}:');
|
|
|
|
onDismiss?.call();
|
|
|
|
},
|
|
|
|
child: Tooltip(
|
|
|
|
richMessage: TextSpan(
|
|
|
|
children: [
|
2025-02-06 15:04:04 +08:00
|
|
|
TextSpan(
|
|
|
|
text: ':${element.pack.prefix}${element.alias}:\n',
|
|
|
|
style: GoogleFonts.robotoMono()),
|
2025-02-04 02:33:19 +08:00
|
|
|
TextSpan(text: element.name).bold(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
width: 48,
|
|
|
|
height: 48,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
child: UniversalImage(
|
|
|
|
sn.getAttachmentUrl(element.attachment.rid),
|
|
|
|
width: 48,
|
|
|
|
height: 48,
|
|
|
|
cacheHeight: 48,
|
|
|
|
cacheWidth: 48,
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
|
|
|
})
|
|
|
|
.expand((ele) => ele)
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|