commentMenu method
- BuildContext context,
- WidgetRef ref
A popup menu button that allows the user to edit or delete their comment.
Implementation
PopupMenuButton commentMenu(BuildContext context, WidgetRef ref) {
return PopupMenuButton<String>(
itemBuilder: (_) => [
("edit", t.generics.edit),
("delete", t.generics.delete),
]
.map(
(entry) => PopupMenuItem<String>(
value: entry.$1,
child: Text(entry.$2),
),
)
.toList(),
onSelected: (value) => switch (value) {
"edit" => ref
.read(commentFormProvider(commentSectionID).notifier)
.update((state) => comment.copyWith(isEdited: true)),
"delete" => yesAbortDialog(
context: context,
title: t.generics.areYouSure,
body: t.comment.deleteMessage,
).then((result) async {
if (result == DialogAction.yes) {
final isConnected = ref.read(isConnectedProvider);
if (!isConnected) return context.notConnectedDialog();
ref
.read(firestoreServiceProvider)
.deleteComment(commentSectionID, comment);
}
}),
_ => null,
},
);
}