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