Make showContextMenu more generic

This commit is contained in:
Henry Hiles 2025-11-28 18:30:13 -05:00
commit 40461aabbf
No known key found for this signature in database
2 changed files with 20 additions and 17 deletions

View file

@ -3,7 +3,7 @@ import "package:flutter/material.dart";
extension ShowContextMenu on BuildContext {
void showContextMenu({
required Offset globalPosition,
required VoidCallback onTap,
required List<PopupMenuEntry> children,
}) {
final overlay = Overlay.of(this).context.findRenderObject() as RenderBox;
@ -16,20 +16,7 @@ extension ShowContextMenu on BuildContext {
overlay.size.height - globalPosition.dy,
),
color: Theme.of(this).colorScheme.surfaceContainerHighest,
items: [
PopupMenuItem(
onTap: onTap,
child: ListTile(leading: Icon(Icons.reply), title: Text("Reply")),
),
PopupMenuItem(
onTap: onTap,
child: ListTile(leading: Icon(Icons.edit), title: Text("Edit")),
),
PopupMenuItem(
onTap: onTap,
child: ListTile(leading: Icon(Icons.delete), title: Text("Delete")),
),
],
items: children,
);
}
}

View file

@ -39,6 +39,22 @@ class RoomChat extends HookConsumerWidget {
final replyToMessage = useState<Message?>(null);
final memberListOpened = useState<bool>(showMembersByDefault);
final theme = Theme.of(context);
List<PopupMenuEntry> getMessageOptions(Message message) => [
PopupMenuItem(
onTap: () => replyToMessage.value = message,
child: ListTile(leading: Icon(Icons.reply), title: Text("Reply")),
),
PopupMenuItem(
onTap: () {},
child: ListTile(leading: Icon(Icons.edit), title: Text("Edit")),
),
PopupMenuItem(
onTap: () {},
child: ListTile(leading: Icon(Icons.delete), title: Text("Delete")),
),
];
return ref
.watch(CurrentRoomController.provider)
.betterWhen(
@ -87,7 +103,7 @@ class RoomChat extends HookConsumerWidget {
required index,
}) => context.showContextMenu(
globalPosition: details.globalPosition,
onTap: () => replyToMessage.value = message,
children: getMessageOptions(message),
),
onMessageLongPress:
(
@ -97,7 +113,7 @@ class RoomChat extends HookConsumerWidget {
required index,
}) => context.showContextMenu(
globalPosition: details.globalPosition,
onTap: () => replyToMessage.value = message,
children: getMessageOptions(message),
),
builders: Builders(
loadMoreBuilder: (_) => Loading(),