feat(logging): add global error handler

This commit is contained in:
qzl
2026-04-01 14:18:22 +08:00
parent bb9e3bf91b
commit 67f14d6cec
2 changed files with 31 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import 'package:flutter/foundation.dart';
import 'logger.dart';
class AppErrorHandler {
final Logger _logger = getLogger('flutter.error');
void register() {
FlutterError.onError = (details) {
_logger.error(
message: 'FlutterError: ${details.exceptionAsString()}',
error: details.exceptionAsString(),
stackTrace: details.stack ?? StackTrace.current,
extra: {'context': 'FlutterError.onError'},
);
FlutterError.presentError(details);
};
}
}