gpt4 book ai didi

flutter - Flutter添加Sentry的正确方法

转载 作者:行者123 更新时间:2023-12-05 01:36:40 31 4
gpt4 key购买 nike

来自 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);
});

但我的 IDE 说 onError 已弃用。

enter image description here

解决这个问题的正确方法是什么?我不能在 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,
);
});
}

关于flutter - Flutter添加Sentry的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61741153/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com