From e5381dd5e0264f5661a33c7b227dfcccb6f2e0d3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 16 Oct 2024 00:02:18 +0800 Subject: [PATCH] :sparkles: Support more mouse related actions --- lib/screens/chat.dart | 9 ++- lib/widgets/chat/chat_event_list.dart | 98 +++++++++++++++------------ lib/widgets/posts/post_action.dart | 8 ++- 3 files changed, 68 insertions(+), 47 deletions(-) diff --git a/lib/screens/chat.dart b/lib/screens/chat.dart index 49199c4..0dcd29c 100644 --- a/lib/screens/chat.dart +++ b/lib/screens/chat.dart @@ -47,16 +47,19 @@ class ChatListShell extends StatelessWidget { direction: Axis.horizontal, divider: ResizableDivider( thickness: 0.3, - color: Theme.of(context).dividerColor, + color: Theme.of(context).dividerColor.withOpacity(0.3), ), children: [ const ResizableChild( minSize: 280, maxSize: 520, - size: ResizableSize.pixels(320), + size: ResizableSize.pixels(360), child: ChatList(), ), - ResizableChild(child: child ?? const EmptyPagePlaceholder()), + ResizableChild( + minSize: 280, + child: child ?? const EmptyPagePlaceholder(), + ), ], ), ); diff --git a/lib/widgets/chat/chat_event_list.dart b/lib/widgets/chat/chat_event_list.dart index 03bebad..14ba17c 100644 --- a/lib/widgets/chat/chat_event_list.dart +++ b/lib/widgets/chat/chat_event_list.dart @@ -1,3 +1,4 @@ +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:get/get.dart'; @@ -34,6 +35,24 @@ class ChatEventList extends StatelessWidget { return a.createdAt.difference(b.createdAt).inMinutes <= 3; } + void _openActions(BuildContext context, Event item) { + showModalBottomSheet( + useRootNavigator: true, + context: context, + builder: (context) => ChatEventAction( + channel: channel, + realm: channel.realm, + item: item, + onEdit: () { + onEdit(item); + }, + onReply: () { + onReply(item); + }, + ), + ); + } + @override Widget build(BuildContext context) { return CustomScrollView( @@ -65,50 +84,45 @@ class ChatEventList extends StatelessWidget { final item = chatController.currentEvents[index].data; - return GestureDetector( - behavior: HitTestBehavior.opaque, - child: Builder(builder: (context) { - final widget = ChatEvent( - key: Key('m${item!.uuid}'), - item: item, - isMerged: isMerged, - chatController: chatController, - ).paddingOnly( - top: !isMerged ? 8 : 0, - bottom: !hasMerged ? 8 : 0, - ); + return TapRegion( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + child: Builder(builder: (context) { + final widget = ChatEvent( + key: Key('m${item!.uuid}'), + item: item, + isMerged: isMerged, + chatController: chatController, + ).paddingOnly( + top: !isMerged ? 8 : 0, + bottom: !hasMerged ? 8 : 0, + ); - if (noAnimated) { - return widget; - } else { - return widget - .animate( - key: Key('animated-m${item.uuid}'), - ) - .slideY( - curve: Curves.fastLinearToSlowEaseIn, - duration: 250.ms, - begin: 0.5, - end: 0, - ); + if (noAnimated) { + return widget; + } else { + return widget + .animate( + key: Key('animated-m${item.uuid}'), + ) + .slideY( + curve: Curves.fastLinearToSlowEaseIn, + duration: 250.ms, + begin: 0.5, + end: 0, + ); + } + }), + onLongPress: () { + _openActions(context, item!); + }, + ), + onTapInside: (event) { + if (event.buttons == kSecondaryMouseButton) { + _openActions(context, item!); + } else if (event.buttons == kMiddleMouseButton) { + onReply(item!); } - }), - onLongPress: () { - showModalBottomSheet( - useRootNavigator: true, - context: context, - builder: (context) => ChatEventAction( - channel: channel, - realm: channel.realm, - item: item!, - onEdit: () { - onEdit(item); - }, - onReply: () { - onReply(item); - }, - ), - ); }, ); }, diff --git a/lib/widgets/posts/post_action.dart b/lib/widgets/posts/post_action.dart index 71bc5d3..245ac8d 100644 --- a/lib/widgets/posts/post_action.dart +++ b/lib/widgets/posts/post_action.dart @@ -91,17 +91,21 @@ class _PostActionState extends State { setState(() => _isBusy = true); + final double width = hasMultipleAttachment ? 640 : 480; + final screenshot = ScreenshotController(); final image = await screenshot.captureFromLongWidget( MediaQuery( - data: MediaQuery.of(context), + data: MediaQuery.of(context).copyWith( + size: Size(width, double.infinity), + ), child: PostShareImage(item: widget.item), ), context: context, pixelRatio: 2, constraints: BoxConstraints( minWidth: 480, - maxWidth: hasMultipleAttachment ? 640 : 480, + maxWidth: width, minHeight: 640, maxHeight: double.infinity, ),