Make showContextMenu more generic
This commit is contained in:
parent
b9bc345b56
commit
40461aabbf
2 changed files with 20 additions and 17 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue