Skip to content

Commit

Permalink
feat: confim condition delete (#63)
Browse files Browse the repository at this point in the history
* chore: create generic confirm dialog widget

* feat: add confirm dialog to delete a custom condition
  • Loading branch information
VytorCalixto authored Nov 24, 2024
1 parent c860e16 commit 4022454
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/common/widgets/confirm_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class ConfirmDialog extends StatelessWidget {
const ConfirmDialog({
super.key,
required this.title,
this.description,
});

final String title;
final String? description;

@override
Widget build(BuildContext context) {
final localization = AppLocalizations.of(context)!;

return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
child: Column(
children: [
if (description != null) Text(description!),
],
),
),
actions: [
OutlinedButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(localization.no_button),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(localization.yes_button),
),
],
);
}
}
13 changes: 13 additions & 0 deletions lib/features/conditions/custom_conditions_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:battlemaster/common/widgets/confirm_dialog.dart';
import 'package:battlemaster/database/database.dart';
import 'package:battlemaster/features/analytics/analytics_service.dart';
import 'package:battlemaster/features/conditions/providers/conditions_provider.dart';
Expand Down Expand Up @@ -83,6 +84,18 @@ class CustomConditionsPage extends StatelessWidget {
child: IconButton(
icon: Icon(MingCute.delete_2_fill),
onPressed: () async {
final confirm = await showDialog<bool>(
context: context,
builder: (context) => ConfirmDialog(
title: localization
.delete_condition_dialog_title(
condition.name,
),
),
);
if (confirm == null || !confirm) {
return;
}
await conditionsProvider
.deleteCondition(condition);
},
Expand Down
10 changes: 10 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,16 @@
"@condition_description_validation_text": {
"description": "The validation text for the condition description input."
},
"delete_condition_dialog_title": "Delete condition \"{name}\"?",
"@delete_condition_dialog_title": {
"description": "Delete condition dialog title",
"placeholders": {
"name": {
"type": "String",
"example": "Poisoned"
}
}
},
"made_with_love": "Made with ❤️ in 🇧🇷",
"@made_with_love": {
"description": "The message to show the app was made with love."
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"condition_name_validation_text": "O nome é obrigatório",
"description_label": "Descrição",
"condition_description_validation_text": "A descrição é obrigatória",
"delete_condition_dialog_title": "Apagar condição \"{name}\"?",
"made_with_love": "Feito com ❤️ no 🇧🇷",
"copyright": "© Battlemaster 2024",
"log_type_add_combatant": "Combatente adicionado",
Expand Down

0 comments on commit 4022454

Please sign in to comment.