From ae0f9df04152e966947db7ff6225fc49411a07e4 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 27 Jan 2023 03:49:25 +0200 Subject: [PATCH 1/2] Prevent multiple UI errors from showing multiple alerts [skip ci] --- lib/main.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index a8d0064f4..0dcbe6b6d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -50,6 +50,7 @@ import 'package:cake_wallet/wallet_type_utils.dart'; final navigatorKey = GlobalKey(); final rootKey = GlobalKey(); final RouteObserver routeObserver = RouteObserver(); +bool hasError = false; Future main() async { @@ -206,11 +207,16 @@ void _sendExceptionFile() async { } void _onError(FlutterErrorDetails errorDetails) { + if (hasError) { + return; + } + + hasError = true; _saveException(errorDetails.exception.toString(), errorDetails.stack); WidgetsBinding.instance.addPostFrameCallback( - (timeStamp) { - showPopUp( + (timeStamp) async { + await showPopUp( context: navigatorKey.currentContext!, builder: (context) { return AlertWithTwoActions( @@ -229,6 +235,8 @@ void _onError(FlutterErrorDetails errorDetails) { ); }, ); + + hasError = false; }, ); } From 4704d7060527931bea1c4f2d0218db845e27ffe1 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Mon, 30 Jan 2023 19:33:40 +0200 Subject: [PATCH 2/2] Save exceptions if happened while there is an already existing report dialog [skip ci] --- lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0dcbe6b6d..af7bb9eff 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -207,12 +207,12 @@ void _sendExceptionFile() async { } void _onError(FlutterErrorDetails errorDetails) { + _saveException(errorDetails.exception.toString(), errorDetails.stack); + if (hasError) { return; } - hasError = true; - _saveException(errorDetails.exception.toString(), errorDetails.stack); WidgetsBinding.instance.addPostFrameCallback( (timeStamp) async {