Refactor codebase using ConfirmDialog whenever possible

This commit is contained in:
2023-06-03 11:59:09 +02:00
parent f0da6f2596
commit e26a1e9598
4 changed files with 63 additions and 93 deletions

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import '../../../../widget/confirmDialog.dart';
class GradeAverage extends StatefulWidget {
const GradeAverage({Key? key}) : super(key: key);
@ -33,22 +35,18 @@ class _GradeAverageState extends State<GradeAverage> {
title: const Text("Notendurschnittsrechner"),
actions: [
IconButton(onPressed: () {
showDialog(context: context, builder: (context) {
return AlertDialog(
title: const Text("Zurücksetzen?"),
content: const Text("Alle Einträge werden entfernt."),
actions: [
TextButton(onPressed: () {
Navigator.of(context).pop();
}, child: const Text("Abbrechen")),
TextButton(onPressed: () {
grades.clear();
setState(() {});
Navigator.of(context).pop();
}, child: const Text("Zurücksetzen"))
],
);
});
showDialog(
context: context,
builder: (context) => ConfirmDialog(
title: "Zurücksetzen?",
content: "Alle Einträge werden entfernt.",
confirmButton: "Zurücksetzen",
onConfirm: () {
grades.clear();
setState(() {});
},
),
);
}, icon: const Icon(Icons.delete_forever)),
PopupMenuButton<bool>(
enableFeedback: true,
@ -71,21 +69,15 @@ class _GradeAverageState extends State<GradeAverage> {
});
if(grades.isNotEmpty) {
showDialog(context: context, builder: (context) {
return AlertDialog(
title: const Text("Notensystem wechseln"),
content: const Text("Beim wechsel des Notensystems werden alle Einträge zurückgesetzt."),
actions: [
TextButton(onPressed: () {
Navigator.of(context).pop();
}, child: const Text("Abbrechen")),
TextButton(onPressed: () {
switchSystem();
Navigator.of(context).pop();
}, child: const Text("Fortfahren")),
],
);
});
showDialog(
context: context,
builder: (context) => ConfirmDialog(
title: "Notensystem wechseln",
content: "Beim wechsel des Notensystems werden alle Einträge zurückgesetzt.",
confirmButton: "Fortfahren",
onConfirm: () => switchSystem(),
),
);
} else {
switchSystem();
}