init method

  1. @override
void init({
  1. required String iOSAppId,
  2. required String androidAppId,
  3. String? channel,
})
override

Implementation

@override
void init(
    {required String iOSAppId,
    required String androidAppId,
    String? channel}) {
  // 先将 onError 保存起来
  var onError = FlutterError.onError;
  // onError是FlutterError的一个静态属性,它有一个默认的处理方法 dumpErrorToConsole
  FlutterError.onError = (errorDetails) {
    reportException(
        exception: "${errorDetails.exception}",
        stackTrace: "${errorDetails.stack}");
    // 调用默认的onError处理
    onError?.call(errorDetails);
  };
  // 官方推荐使用
  PlatformDispatcher.instance.onError = (exception, stackTrace) {
    reportException(exception: "$exception", stackTrace: "$stackTrace");
    if (kDebugMode) {
      print("$exception\n$stackTrace");
    }
    return true;
  };
  methodChannel.invokeMethod('init', {
    "appId": Platform.isAndroid ? androidAppId : iOSAppId,
    'channel': channel,
  });
}