From ae0f9df04152e966947db7ff6225fc49411a07e4 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 27 Jan 2023 03:49:25 +0200 Subject: [PATCH] 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; }, ); }