【问题标题】:flutter sentry The function 'runZonedGuarded' isn't defined颤振哨兵未定义函数“runZonedGuarded”
【发布时间】:2021-01-20 06:55:38
【问题描述】:

我正在尝试在我的颤振项目中添加哨兵。 从文档中,我看到我必须这样做

runZonedGuarded(
 () => runApp(MyApp(flutterI18nDelegate)),
   (error, stackTrace) {
try {
  sentry.captureException(
    exception: error,
    stackTrace: stackTrace,
  );
  print('Error sent to sentry.io: $error');
} catch (e) {
  print('Sending report to sentry.io failed: $e');
  print('Original error: $error');
}
});

但是我收到了这个错误

The function 'runZonedGuarded' isn't defined. Try importing the library that defines 'runZonedGuarded', correcting the name to the name of an existing function, or defining a function named

谢谢。

我的飞镖和颤振版本

Flutter 1.20.2 • channel beta • https://github.com/flutter/flutter.git
Framework • revision bbfbf1770c (8 weeks ago) • 2020-08-13 08:33:09 -0700
Engine • revision 9d5b21729f

工具• Dart 2.9.1

【问题讨论】:

  • 你需要import 'dart:async';

标签: flutter sentry


【解决方案1】:

runZonedGuardeddart:async 上定义。

完整的sn-p是:

import 'dart:async'; 

// Wrap your 'runApp(MyApp())' as follows:

void main() async {
  runZonedGuarded(
    () => runApp(MyApp()),
    (error, stackTrace) {
      await sentry.captureException(
        exception: error,
        stackTrace: stackTrace,
      );
    },
  );
}

We've added to the docs.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 2021-05-01
    • 2020-08-28
    相关资源
    最近更新 更多