From a5cdafcb659d0f03ffa1658ff09e1d40063fa4bc Mon Sep 17 00:00:00 2001 From: bluearevalo <90929912+bluearevalo@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:24:13 -0400 Subject: [PATCH] Added null checks, error handling, and used non-null version of l10n --- lib/utils/error_reporter.dart | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/utils/error_reporter.dart b/lib/utils/error_reporter.dart index f3b3bfabd..76e39c193 100644 --- a/lib/utils/error_reporter.dart +++ b/lib/utils/error_reporter.dart @@ -9,15 +9,26 @@ class ErrorReporter { const ErrorReporter(this.context, [this.message]); void onErrorCallback(Object error, [StackTrace? stackTrace]) async { - Logs().e(message ?? 'Error caught', error, stackTrace); - // #Pangea - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - L10n.of(context)!.oopsSomethingWentWrong, - ), + Logs().e(message ?? 'Error caught', error, stackTrace); + // #Pangea + // Attempt to retrieve the L10n instance using the current context + final L10n? l10n = L10n.of(context); + + // Check if the L10n instance is null + if (l10n == null) { + // Log an error message saying that the localization object is null + Logs().e('Localization object is null, cannot show error message.'); + // Exits early to prevent further execution + return; + } + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + l10n.oopsSomethingWentWrong, // Use the non-null L10n instance to get the error message ), - ); + ), + ); +} // final text = '$error\n${stackTrace ?? ''}'; // await showAdaptiveDialog( // context: context, @@ -64,4 +75,4 @@ class ErrorReporter { // ); // Pangea# } -} +