mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
Add initial alert for errors
This commit is contained in:
parent
51ea377a52
commit
03ea516e63
1 changed files with 41 additions and 35 deletions
|
@ -9,8 +9,10 @@ import 'package:cake_wallet/entities/preferences_key.dart';
|
||||||
import 'package:cake_wallet/ionia/ionia_category.dart';
|
import 'package:cake_wallet/ionia/ionia_category.dart';
|
||||||
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
import 'package:cake_wallet/ionia/ionia_merchant.dart';
|
||||||
import 'package:cake_wallet/src/screens/failure_page.dart';
|
import 'package:cake_wallet/src/screens/failure_page.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||||
import 'package:cake_wallet/store/yat/yat_store.dart';
|
import 'package:cake_wallet/store/yat/yat_store.dart';
|
||||||
import 'package:cake_wallet/themes/theme_list.dart';
|
import 'package:cake_wallet/themes/theme_list.dart';
|
||||||
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
@ -53,13 +55,19 @@ Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
FlutterError.onError = (errorDetails) {
|
FlutterError.onError = (errorDetails) {
|
||||||
print("@@@@@@@@@@@@@@@");
|
print("@@@@@@@@@@@@@@@@@ in on error");
|
||||||
print("FlutterError.onError");
|
print(errorDetails.exception.toString());
|
||||||
print(errorDetails);
|
_onError(errorDetails);
|
||||||
_saveException(errorDetails.exception.toString(), errorDetails.stack);
|
_saveException(errorDetails.exception.toString(), errorDetails.stack);
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorWidget.builder = (errorDetails) {
|
ErrorWidget.builder = (errorDetails) {
|
||||||
|
print("@@@@@@@@@@@@@@@@@ in widget error");
|
||||||
|
// TODO: uncomment
|
||||||
|
// if (kDebugMode) {
|
||||||
|
// return ErrorWidget(errorDetails.exception);
|
||||||
|
// }
|
||||||
|
|
||||||
return FailurePage(
|
return FailurePage(
|
||||||
error: errorDetails.exception.toString(),
|
error: errorDetails.exception.toString(),
|
||||||
stackTrace: errorDetails.stack,
|
stackTrace: errorDetails.stack,
|
||||||
|
@ -161,38 +169,8 @@ Future<void> main() async {
|
||||||
initialMigrationVersion: 17);
|
initialMigrationVersion: 17);
|
||||||
runApp(App());
|
runApp(App());
|
||||||
}, (error, stackTrace) async {
|
}, (error, stackTrace) async {
|
||||||
print("@@@@@@@@@@@@@@@@");
|
print("@@@@@@@@@@@@@@@@ in run zone guard");
|
||||||
print(error);
|
_onError(FlutterErrorDetails(exception: error, stack: stackTrace));
|
||||||
print(stackTrace);
|
|
||||||
_saveException(error.toString(), stackTrace);
|
|
||||||
// TODO: this will trigger even there is no fatal error occurred so better not build a new app instance
|
|
||||||
// final sharedPreferences = await SharedPreferences.getInstance();
|
|
||||||
// final theme = ThemeList.deserialize(
|
|
||||||
// raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ?? 0);
|
|
||||||
//
|
|
||||||
// final savedLanguageCode =
|
|
||||||
// sharedPreferences.getString(PreferencesKey.currentLanguageCode) ??
|
|
||||||
// await LanguageService.localeDetection();
|
|
||||||
// runApp(
|
|
||||||
// MaterialApp(
|
|
||||||
// debugShowCheckedModeBanner: true,
|
|
||||||
// theme: theme.themeData,
|
|
||||||
// localizationsDelegates: [
|
|
||||||
// S.delegate,
|
|
||||||
// GlobalCupertinoLocalizations.delegate,
|
|
||||||
// GlobalMaterialLocalizations.delegate,
|
|
||||||
// GlobalWidgetsLocalizations.delegate,
|
|
||||||
// ],
|
|
||||||
// supportedLocales: S.delegate.supportedLocales,
|
|
||||||
// locale: Locale(savedLanguageCode),
|
|
||||||
// home: Scaffold(
|
|
||||||
// body: FailurePage(
|
|
||||||
// error: error.toString(),
|
|
||||||
// stackTrace: stackTrace,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,6 +188,34 @@ void _saveException(String? error, StackTrace? stackTrace) async {
|
||||||
await file.writeAsString(jsonEncode(exception), mode: FileMode.append);
|
await file.writeAsString(jsonEncode(exception), mode: FileMode.append);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onError(FlutterErrorDetails details) {
|
||||||
|
print("#############");
|
||||||
|
print(details.exception.toString());
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback(
|
||||||
|
(timeStamp) {
|
||||||
|
showPopUp<void>(
|
||||||
|
context: navigatorKey.currentContext!,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertWithTwoActions(
|
||||||
|
isDividerExist: true,
|
||||||
|
alertTitle: S.of(context).error,
|
||||||
|
alertContent: "Oops, we got some error.\n\nPlease send crash report to our support team to make the application better.",
|
||||||
|
rightButtonText: S.of(context).send,
|
||||||
|
leftButtonText: "Don't send",
|
||||||
|
actionRightButton: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
actionLeftButton: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
_saveException(details.exception.toString(), details.stack);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> initialSetup(
|
Future<void> initialSetup(
|
||||||
{required SharedPreferences sharedPreferences,
|
{required SharedPreferences sharedPreferences,
|
||||||
required Box<Node> nodes,
|
required Box<Node> nodes,
|
||||||
|
|
Loading…
Reference in a new issue