From 361fd049718b20d4e89094251734987cbe47ea7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20K=C3=B6rber?= <56073945+jakobkoerber@users.noreply.github.com> Date: Sat, 30 Nov 2024 12:46:28 +0100 Subject: [PATCH] Fix Errors occurring after View is already disposed --- .../views/event_creation_view.dart | 2 +- .../homeWidget/cafeteria_widget_view.dart | 29 ++++++++++--------- .../views/settings_view.dart | 4 ++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/calendarComponent/views/event_creation_view.dart b/lib/calendarComponent/views/event_creation_view.dart index 55fca45f..edd8a3b6 100644 --- a/lib/calendarComponent/views/event_creation_view.dart +++ b/lib/calendarComponent/views/event_creation_view.dart @@ -106,8 +106,8 @@ class EventCreationView extends ConsumerWidget { .read(calendarAdditionViewModel(calendarEvent)) .saveEvent() .then((value) { - ref.invalidate(calendarAdditionViewModel); if (context.mounted) { + ref.invalidate(calendarAdditionViewModel); context.canPop() ? context.pop() : context.go(calendar); } }) diff --git a/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart b/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart index fd978e20..76340f33 100644 --- a/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart +++ b/lib/placesComponent/views/homeWidget/cafeteria_widget_view.dart @@ -56,19 +56,22 @@ class _CafeteriaWidgetViewState extends ConsumerState { Icons.filter_list, color: context.primaryColor, ), - onTap: () => showModalBottomSheet( - builder: (context) => PreferenceSelectionView( - data: ref - .read(cafeteriasViewModel) - .getCafeteriaEntries(context), - entry: context.tr("cafeteria"), - ), - context: context, - useRootNavigator: true, - isScrollControlled: true, - useSafeArea: true, - showDragHandle: true, - ), + onTap: () => context.mounted + ? showModalBottomSheet( + builder: (context) => + PreferenceSelectionView( + data: ref + .read(cafeteriasViewModel) + .getCafeteriaEntries(context), + entry: context.tr("cafeteria"), + ), + context: context, + useRootNavigator: true, + isScrollControlled: true, + useSafeArea: true, + showDragHandle: true, + ) + : null, ), ], ), diff --git a/lib/settingsComponent/views/settings_view.dart b/lib/settingsComponent/views/settings_view.dart index 51ef264a..103289cd 100644 --- a/lib/settingsComponent/views/settings_view.dart +++ b/lib/settingsComponent/views/settings_view.dart @@ -81,7 +81,9 @@ class SettingsView extends ConsumerWidget { Widget _resetPreferencesButton(BuildContext context, WidgetRef ref) { return ListTile( - onTap: () => ref.read(onboardingViewModel).resetPreferences(ref), + onTap: () => context.mounted + ? ref.read(onboardingViewModel).resetPreferences(ref) + : null, dense: true, title: Text( context.tr("resetPreferences"),