build method

void build(
  1. Widget app, {
  2. OnReleaseLogReport? report,
  3. int environment = 0,
  4. OnCrashCollectCall? crashCollectCall,
  5. OnCompletedCall? completedCall,
})

构建crash节点 app 根节点 report 正式环境上报回调 environment 0-正式;1-预发;2-测试; crashCollectCall crash收集回调 completedCall 处理完成回调

Implementation

void build(Widget app,
    {OnReleaseLogReport? report,
    int environment = 0,
    OnCrashCollectCall? crashCollectCall,
    OnCompletedCall? completedCall}) {
  const bool inProduction = bool.fromEnvironment("dart.vm.product");
  FlutterError.onError = (FlutterErrorDetails details) {
    if (inProduction) {
      Zone.current.handleUncaughtError(details.exception, details.stack ?? StackTrace.empty);
    } else {
      FlutterError.dumpErrorToConsole(details);
    }
    _crashHandler(completedCall, crashCollectCall, report, details.exception, environment);
  };
  // flutter 3.10.1 runZonedGuarded暂不支持
  // runZonedGuarded(() => runApp(app), (Object error, StackTrace stack) {
  //   _crashHandler(completedCall, crashCollectCall, report, error, environment);
  // });
  // runZonedGuarded<Future<Null>>(() async {
  //   runApp(app);
  // }, (error, stackTrace) async {
  //   _crashHandler(completedCall, crashCollectCall, report, error, environment);
  // });
  runApp(app);
}