Skip to content

Commit

Permalink
Add error handling for deleting contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedHanafy725 committed Oct 2, 2024
1 parent c826c37 commit bf1a567
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions app/lib/widgets/wallets/contact_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,30 @@ class _ContactCardWidgetState extends State<ContactCardWidget> {
setState(() {
deleteLoading = true;
});
//TODO: Show snack in case of failure
await deleteContact(widget.name);
widget.onDeleteContact!(widget.name);

setState(() {
deleteLoading = false;
});
try {
await deleteContact(widget.name);
widget.onDeleteContact!(widget.name);
} catch (e) {
print('Failed to delete contact due to $e');
if (context.mounted) {
final loadingFarmsFailure = SnackBar(
content: Text(
'Failed to delete',
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Theme.of(context).colorScheme.errorContainer),
),
duration: const Duration(seconds: 3),
);
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(loadingFarmsFailure);
}
} finally {
setState(() {
deleteLoading = false;
});
}
}

void _showDeleteConfirmationDialog() {
Expand Down

0 comments on commit bf1a567

Please sign in to comment.