loginKakao method

Future<_KakaoLoginInfo?> loginKakao()

Implementation

Future<_KakaoLoginInfo?> loginKakao() async {
  String accessToken;
  int? userId;
  if (await isKakaoTalkInstalled()) {
    try {
      accessToken = (await UserApi.instance.loginWithKakaoTalk()).accessToken;
      userId = (await UserApi.instance.accessTokenInfo()).id;
    } catch (error) {
      if (error is PlatformException && error.code == 'CANCELED') {
        dev.log(error.toString(), name: 'CANCELED');
        return null;
      } else {
        dev.log(error.toString(), name: '`loginWithKakaoTalk()`');
      }
      // 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인
      try {
        accessToken =
            (await UserApi.instance.loginWithKakaoAccount()).accessToken;
        userId = (await UserApi.instance.accessTokenInfo()).id;
      } catch (error) {
        dev.log(error.toString(),
            name: '`isKakaoTalkInstalled()` but `loginWithKakaoAccount()`');
        return null;
      }
    }
  } else {
    try {
      accessToken =
          (await UserApi.instance.loginWithKakaoAccount()).accessToken;
      userId = (await UserApi.instance.accessTokenInfo()).id;
    } catch (error) {
      dev.log(error.toString(), name: '`loginWithKakaoAccount()`');
      return null;
    }
  }
  return _KakaoLoginInfo(accessToken: accessToken, userId: userId);
}