Prevent multiple UI errors from showing multiple alerts [skip ci]

OmarHatem committed Jan 27, 2023 at 03:49 UTC ae0f9df04152e966947db7ff6225fc49411a07e4
1 file changed +10 -2
lib/main.dart
+10 -2
@@ -50,6 +50,7 @@ import 'package:cake_wallet/wallet_type_utils.dart';
50 final navigatorKey = GlobalKey<NavigatorState>();
51 final rootKey = GlobalKey<RootState>();
52 final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
53 +bool hasError = false;
54
55 Future<void> main() async {
56
@@ -206,11 +207,16 @@ void _sendExceptionFile() async {
207 }
208
209 void _onError(FlutterErrorDetails errorDetails) {
210 + if (hasError) {
211 + return;
212 + }
213 +
214 + hasError = true;
215 _saveException(errorDetails.exception.toString(), errorDetails.stack);
216
217 WidgetsBinding.instance.addPostFrameCallback(
212 - (timeStamp) {
213 - showPopUp<void>(
218 + (timeStamp) async {
219 + await showPopUp<void>(
220 context: navigatorKey.currentContext!,
221 builder: (context) {
222 return AlertWithTwoActions(
@@ -229,6 +235,8 @@ void _onError(FlutterErrorDetails errorDetails) {
235 );
236 },
237 );
238 +
239 + hasError = false;
240 },
241 );
242 }