signInWithApple method

Future<List?> signInWithApple(
  1. BuildContext context,
  2. String name, {
  3. Position? position,
  4. Widget? page,
})

Implementation

Future<List?> signInWithApple(BuildContext context, String name,
    {Position? position, Widget? page}) async {
  final rawNonce = generateNonce();
  final nonce = sha256ofString(rawNonce);
  var applefailed = false;
  final appleCredential = await SignInWithApple.getAppleIDCredential(scopes: [
    AppleIDAuthorizationScopes.email,
    AppleIDAuthorizationScopes.fullName
  ], nonce: nonce).onError((error, stackTrace) {
    // SellonRouter.pop(context);
    return AuthorizationCredentialAppleID(authorizationCode: 'null');
  });

  if (appleCredential.authorizationCode == "null"){
    SellonRouter.pop(context);
  }
  if (appleCredential.identityToken == null) {
    SellonRouter.pop(context);
  }

  // final appleCredential = await SignInWithApple.getAppleIDCredential(
  //   scopes: [
  //     AppleIDAuthorizationScopes.email,
  //     AppleIDAuthorizationScopes.fullName,
  //   ],
  //   nonce: nonce,
  // ).onError((error, stackTrace) {
  //   SellonRouter.pop(context);
  //
  //   // return null;
  //   // return error;
  // });

  var nameresult = appleCredential.familyName != null
      ? appleCredential.familyName
      : appleCredential.givenName != null
      ? appleCredential.givenName
      : name;

  // if (appleCredential == null) {
  //   SellonRouter.pop(context);
  // }
  Preferences.setNonceApple(nonce);
  if (appleCredential.identityToken != null) {
    Preferences.setIdTokenApple(appleCredential.identityToken!);
  }
  if (appleCredential.email != null) {
    Preferences.setEmailApple(appleCredential.email!);

    gotAgain(
        position: position,
        appleCredential: appleCredential,
        context: context,
        name: nameresult,
        email: appleCredential.email,
        page: page);
  } else {
    Preferences.getEmailApple().then((valueemailnya) {
      if (valueemailnya != null) {
        gotAgain(
            position: position,
            appleCredential: appleCredential,
            context: context,
            name: nameresult,
            email: valueemailnya,
            page: page);
      } else {
        String a = getRandomString(10);
        String email = "${a}@privaterelay.appleid.com";
        gotAgain(
            position: position,
            appleCredential: appleCredential,
            context: context,
            name: nameresult,
            email: email,
            page: page);
      }
    });
  }
}