Skip to content

Commit

Permalink
Merge pull request #89 from andreped:add-clear-db-dialog
Browse files Browse the repository at this point in the history
Add clear DB dialog to improve user-friendliness and safeguard data
  • Loading branch information
andreped authored Aug 6, 2024
2 parents 6068167 + c91de33 commit 0c4e41d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
59 changes: 58 additions & 1 deletion lib/tabs/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,63 @@ class _ExerciseStoreHomePageState extends State<ExerciseStoreHomePage> with Sing
});
}

Future<void> _showConfirmationDialogs() async {
final bool? firstDialogConfirmed = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('⚠️ Confirm Deletion'),
content: const Text('🚨 Clicking this button deletes all the recorded exercise data. Are you sure you want to do this?'),
actions: <Widget>[
TextButton(
child: const Text('No'),
onPressed: () => Navigator.of(context).pop(false),
),
TextButton(
child: const Text('Yes'),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
},
);

if (firstDialogConfirmed == true) {
final bool? secondDialogConfirmed = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('❗️ Are you really sure?'),
content: const Text('💥 Are you really sure you want to lose all your data? There is no going back!'),
actions: <Widget>[
TextButton(
child: const Text('No'),
onPressed: () => Navigator.of(context).pop(false),
),
TextButton(
child: const Text('Yes'),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
},
);

if (secondDialogConfirmed == true) {
await _clearDatabase();

// Show success SnackBar
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('✅ Database cleared successfully!'),
backgroundColor: Colors.green,
duration: const Duration(seconds: 2),
),
);
}
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -93,7 +150,7 @@ class _ExerciseStoreHomePageState extends State<ExerciseStoreHomePage> with Sing
IconButton(
icon: const Icon(Icons.delete_sweep),
onPressed: () async {
await _clearDatabase();
await _showConfirmationDialogs();
},
),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/tabs/inputs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ class _ExerciseSetterState extends State<ExerciseSetter> {

if (isNewHighScore) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('New high score for $exerciseName!'),
content: Text('🚀🎉 New high score for $exerciseName!'),
duration: Duration(seconds: 2),
backgroundColor: Colors.green,
));
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Exercise added successfully'),
content: Text('🎯 Exercise added successfully'),
duration: Duration(seconds: 2),
));
}
Expand Down

0 comments on commit 0c4e41d

Please sign in to comment.