onPressed: () async => showDialog<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Delete item'),
content: const Text('Are you sure you want to delete this item?'),
actions: [
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
child: const Text(
'Delete',
style: TextStyle(color: Colors.white),
),
onPressed: () => Navigator.pop(context, true),
),
TextButton(
child: const Text(
'Cancel',
style: TextStyle(color: Colors.black),
),
onPressed: () => Navigator.pop(context, false),
),
],
),
).then((bool? isDeleted) => isDeleted != null && isDeleted
? ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Item successfully deleted',
textAlign: TextAlign.center,
),
backgroundColor: Colors.red,
),
)
: null)