From abacef3d8ac05d0df92c62b67588500b88625423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Tue, 30 May 2023 18:54:55 +0200 Subject: [PATCH] Only show grade switching Warning when something is entered --- .../more/gradeAverages/gradeAverage.dart | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/screen/pages/more/gradeAverages/gradeAverage.dart b/lib/screen/pages/more/gradeAverages/gradeAverage.dart index 05d8f00..f5dc469 100644 --- a/lib/screen/pages/more/gradeAverages/gradeAverage.dart +++ b/lib/screen/pages/more/gradeAverages/gradeAverage.dart @@ -64,25 +64,32 @@ class _GradeAverageState extends State { )).toList(), onSelected: (e) { - 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: () { - setState(() { - grades.clear(); - gradeSystem = e; - }); - Navigator.of(context).pop(); - }, child: const Text("Fortfahren")), - ], - ); + void switchSystem() => setState(() { + grades.clear(); + gradeSystem = e; }); + 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(); + } + + }, ), ],