From cd07acc3b5ae313ad7a101d53855cfdb9bd8bab6 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sat, 4 Mar 2023 10:29:35 +0100 Subject: [PATCH] fixed flutter analyze issues introduced with new flutter version --- lib/pages/scanner_page.dart | 14 ++++++----- lib/widgets/popup_for_task_done.dart | 24 ++++++++++--------- lib/widgets/submit_form_button.dart | 34 ++++++++++++++------------- lib/widgets/workout_timer_widget.dart | 16 +++++++------ 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/lib/pages/scanner_page.dart b/lib/pages/scanner_page.dart index d809ff9..ebba252 100644 --- a/lib/pages/scanner_page.dart +++ b/lib/pages/scanner_page.dart @@ -20,12 +20,14 @@ class ScannerPage extends StatelessWidget { await loadSettingsFromLocalJSON(); settingsModel.initSettings(); NotificationService().setAllNotifications(); - AwesomeDialog( - context: context, - dialogType: DialogType.success, - title: 'Geschafft', - desc: 'Die Einstellung wurden erfolgreich gespeichert', - ).show(); + if (context.mounted) { + AwesomeDialog( + context: context, + dialogType: DialogType.success, + title: 'Geschafft', + desc: 'Die Einstellung wurden erfolgreich gespeichert', + ).show(); + } } @override diff --git a/lib/widgets/popup_for_task_done.dart b/lib/widgets/popup_for_task_done.dart index fe63907..fbaa65d 100644 --- a/lib/widgets/popup_for_task_done.dart +++ b/lib/widgets/popup_for_task_done.dart @@ -7,17 +7,19 @@ import '../services/pages_service.dart'; void showTaskDonePopup(BuildContext context, Pages page) async { Duration duration = await getTimeTill(page); - await showDialog( - context: context, - builder: (BuildContext context) { - return ChangeNotifierProvider( - create: (context) => TimerProvider(), - child: TaskDonePopup( - duration: duration, - ), - ); - }, - ); + if (context.mounted) { + await showDialog( + context: context, + builder: (BuildContext context) { + return ChangeNotifierProvider( + create: (context) => TimerProvider(), + child: TaskDonePopup( + duration: duration, + ), + ); + }, + ); + } } class TaskDonePopup extends StatelessWidget { diff --git a/lib/widgets/submit_form_button.dart b/lib/widgets/submit_form_button.dart index 4c98c34..f9cb784 100644 --- a/lib/widgets/submit_form_button.dart +++ b/lib/widgets/submit_form_button.dart @@ -17,22 +17,24 @@ class SubmitFormButton extends StatelessWidget { child: ElevatedButton( onPressed: () async { int success = await submitCallback(); - if (success != 0) { - await AwesomeDialog( - context: context, - dialogType: DialogType.success, - title: 'Gespeichert', - desc: 'Der Eintrag wurde erfolgreich gespeichert', - ).show(); - updateTasks(); - pageProvider.swap(); - } else { - await AwesomeDialog( - context: context, - dialogType: DialogType.error, - title: 'Fehler', - desc: 'Der Eintrag konnte nicht gespeichert werden', - ).show(); + if (context.mounted) { + if (success != 0) { + await AwesomeDialog( + context: context, + dialogType: DialogType.success, + title: 'Gespeichert', + desc: 'Der Eintrag wurde erfolgreich gespeichert', + ).show(); + updateTasks(); + pageProvider.swap(); + } else { + await AwesomeDialog( + context: context, + dialogType: DialogType.error, + title: 'Fehler', + desc: 'Der Eintrag konnte nicht gespeichert werden', + ).show(); + } } }, child: const Text('Speichern'), diff --git a/lib/widgets/workout_timer_widget.dart b/lib/widgets/workout_timer_widget.dart index 10f3033..7312ad1 100644 --- a/lib/widgets/workout_timer_widget.dart +++ b/lib/widgets/workout_timer_widget.dart @@ -28,13 +28,15 @@ class WorkoutTimerWidget extends StatelessWidget { workoutProvider.saveWorkout(); tasksProvider.setTaskDone(Pages.timer); }, 'Motivation nach dem Training'); - await AwesomeDialog( - context: context, - dialogType: DialogType.success, - title: 'Gespeichert', - desc: 'Der Eintrag wurde erfolgreich gespeichert', - ).show(); - pageProvider.swap(); + if (context.mounted) { + await AwesomeDialog( + context: context, + dialogType: DialogType.success, + title: 'Gespeichert', + desc: 'Der Eintrag wurde erfolgreich gespeichert', + ).show(); + pageProvider.swap(); + } } if (workoutProvider.isPhaseComplete && !workoutProvider.isWorkoutComplete) {