来自https://flutter.dev/docs/cookbook/maintenance/error-reporting,
runZoned<Future<void>>(() async {
runApp(CrashyApp());
}, onError: (error, stackTrace) {
// Whenever an error occurs, call the `_reportError` function. This sends
// Dart errors to the dev console or Sentry depending on the environment.
_reportError(error, stackTrace);
});
Run Code Online (Sandbox Code Playgroud)
但我的 IDE 说onError已弃用。
解决这个问题的正确方法是什么?我无法提供有关 runZonedGuarded 的任何示例。
这是对我有用的设置:
Future<void> main() async {
final sentry = Sentry.SentryClient(Sentry.SentryOptions(dsn: '[Add dsn URI here]'));
runZonedGuarded(() {
WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (FlutterErrorDetails errorDetails) {
sentry.captureException(
errorDetails.exception,
stackTrace: errorDetails.stack,
);
};
runApp(MyApp());
}, (Object error, StackTrace stackTrace) {
sentry.captureException(
error,
stackTrace: stackTrace,
);
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4058 次 |
| 最近记录: |