hookCrash function
Implementation
void hookCrash(Function main) {
ErrorWidget.builder =
(FlutterErrorDetails errorDetails) => _errorWidgetBuilder(errorDetails);
if (_inProduction) {
FlutterError.onError = (FlutterErrorDetails details) async {
Zone.current.handleUncaughtError(
details.exception, details.stack ?? StackTrace.empty);
};
}
runZoned<Future<void>>(
() async {
LogUtils.d('$TAG runZoned');
main();
LogUtils.d('$TAG runZoned main');
},
onError: (dynamic error, StackTrace stack) {
//捕获异常打印日志
_reportError(error, stack);
},
);
}