Only show grade switching Warning when something is entered

This commit is contained in:
Elias Müller 2023-05-30 18:54:55 +02:00
parent a161378c72
commit abacef3d8a

View File

@ -64,25 +64,32 @@ class _GradeAverageState extends State<GradeAverage> {
)).toList(), )).toList(),
onSelected: (e) { onSelected: (e) {
showDialog(context: context, builder: (context) { void switchSystem() => setState(() {
return AlertDialog( grades.clear();
title: const Text("Notensystem wechseln"), gradeSystem = e;
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: () {
setState(() {
grades.clear();
gradeSystem = e;
});
Navigator.of(context).pop();
}, child: const Text("Fortfahren")),
],
);
}); });
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")),
],
);
});
} else {
switchSystem();
}
}, },
), ),
], ],