refactor(inventory): simplify delete item logic and remove unnecessary parameters
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -309,7 +309,8 @@ class _TrailingActions extends ConsumerWidget {
|
||||
const _TrailingActions({required this.item});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
Widget build(BuildContext context) {
|
||||
final ref = ref;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -348,7 +349,7 @@ class _DeleteButton extends ConsumerWidget {
|
||||
const _DeleteButton({required this.item});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: 'Ta bort',
|
||||
child: IconButton(
|
||||
@@ -371,18 +372,14 @@ class _DeleteButton extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true) return;
|
||||
try {
|
||||
final token = await ref.read(authStateProvider.future);
|
||||
await ref
|
||||
.read(inventoryRepositoryProvider)
|
||||
.deleteInventoryItem(item.id, token: token);
|
||||
ref.invalidate(inventoryProvider);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(mapErrorToUserMessage(e, context))),
|
||||
);
|
||||
if (confirmed == true) {
|
||||
try {
|
||||
await ref.read(inventoryRepositoryProvider).deleteItem(item.id);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(mapErrorToUserMessage(e, context))),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user