Check if widget is mounted before showing popups

OmarHatem committed Feb 7, 2023 at 18:03 UTC bf407bedecc11736865d3b0ea3cc69a07ddd38d3
3 files changed +22 -20
lib/src/screens/send/send_page.dart
+9 -11
@@ -365,17 +365,15 @@ class SendPage extends BasePage {
365 reaction((_) => sendViewModel.state, (ExecutionState state) {
366 if (state is FailureState) {
367 WidgetsBinding.instance.addPostFrameCallback((_) {
368 - if (context.mounted) {
369 - showPopUp<void>(
370 - context: context,
371 - builder: (BuildContext context) {
372 - return AlertWithOneAction(
373 - alertTitle: S.of(context).error,
374 - alertContent: state.error,
375 - buttonText: S.of(context).ok,
376 - buttonAction: () => Navigator.of(context).pop());
377 - });
378 - }
368 + showPopUp<void>(
369 + context: context,
370 + builder: (BuildContext context) {
371 + return AlertWithOneAction(
372 + alertTitle: S.of(context).error,
373 + alertContent: state.error,
374 + buttonText: S.of(context).ok,
375 + buttonAction: () => Navigator.of(context).pop());
376 + });
377 });
378 }
379
lib/utils/exception_handler.dart
+1
@@ -120,6 +120,7 @@ class ExceptionHandler {
120 static bool _ignoreError(String error) {
121 return error.contains("errno = 103") || // SocketException: Software caused connection abort
122 error.contains("errno = 9") || // SocketException: Bad file descriptor
123 + error.contains("errno = 32") || // SocketException: Write failed (OS Error: Broken pipe)
124 error.contains("errno = 54"); // SocketException: Connection reset by peer
125 }
126 }
lib/utils/show_pop_up.dart
+12 -9
@@ -8,13 +8,16 @@ Future<T?> showPopUp<T>({
8 bool useSafeArea = false,
9 bool useRootNavigator = true,
10 RouteSettings? routeSettings
11 -}) {
12 - return showDialog<T>(
13 - context: context,
14 - builder: builder,
15 - barrierDismissible: barrierDismissible,
16 - barrierColor: barrierColor,
17 - useSafeArea: useSafeArea,
18 - useRootNavigator: useRootNavigator,
19 - routeSettings: routeSettings);
11 +}) async {
12 + if (context.mounted) {
13 + return showDialog<T>(
14 + context: context,
15 + builder: builder,
16 + barrierDismissible: barrierDismissible,
17 + barrierColor: barrierColor,
18 + useSafeArea: useSafeArea,
19 + useRootNavigator: useRootNavigator,
20 + routeSettings: routeSettings);
21 + }
22 + return null;
23 }