handleAppleSignInCallBack static method

dynamic handleAppleSignInCallBack({
  1. required DidCompleteWithSignIn onCompleteWithSignIn,
  2. required DidCompleteWithError onCompleteWithError,
})

Implementation

static handleAppleSignInCallBack(
    {required DidCompleteWithSignIn onCompleteWithSignIn,
    required DidCompleteWithError onCompleteWithError}) {
  Future<dynamic> platformCallHandler(MethodCall call) async {
    switch (call.method) {
      case "didCompleteWithSignIn":
        var user = AppleIdUser.fromJson(call.arguments);
        await onCompleteWithSignIn(user);
        break;
      case "didCompleteWithError":
      {
        AppleSignInErrorCode errorCode = AppleSignInErrorCode.unknown;
          int code = call.arguments["code"] ?? 1000;
          switch (code) {
            case 1000:
              errorCode = AppleSignInErrorCode.unknown;
              break;
            case 1001:
              errorCode = AppleSignInErrorCode.canceled;
              break;
            case 1002:
              errorCode = AppleSignInErrorCode.invalidResponse;
              break;
            case 1003:
              errorCode = AppleSignInErrorCode.notHandled;
              break;
            case 1004:
              errorCode = AppleSignInErrorCode.failed;
              break;
          }
          await onCompleteWithError(errorCode);
      }
        break;
    }
  }

  _channel.setMethodCallHandler(platformCallHandler);
}