将哨兵添加到Flutter的正确方法

时间:2020-05-11 23:26:47

标签: flutter sentry

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上找不到任何示例。

2 个答案:

答案 0 :(得分:0)

在Flutter 1.17.0 became obsolete上看起来像(It's a breaking change from Dart 2.8)。您可以这样:


runZonedGuarded(() {
  runApp(CrashyApp());
}, (Object error, StackTrace 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);
});

答案 1 :(得分:0)

这是对我有用的设置:

sessionInfo()

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252   
[3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C                      
[5] LC_TIME=Dutch_Netherlands.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] servr_0.20

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       rstudioapi_0.13  knitr_1.30       magrittr_2.0.1   mnormt_2.0.2     pbivnorm_0.6.0  
 [7] R6_2.5.0         rlang_0.4.9      tools_4.0.3      tmvnsim_1.0-2    xfun_0.19        htmltools_0.5.0 
[13] yaml_2.2.1       digest_0.6.27    lavaan_0.6-7     bookdown_0.21    processx_3.4.5   later_1.1.0.1   
[19] promises_1.1.1   ps_1.4.0         evaluate_0.14    rmarkdown_2.5    blogdown_0.21.50 compiler_4.0.3  
[25] stats4_4.0.3     jsonlite_1.7.1   httpuv_1.5.4