googleLogin method Null safety

Future<AnnouncementLoginData?> googleLogin(
  1. {required String? idToken,
  2. GeneralCallback<AnnouncementLoginData>? callback}
)

Implementation

Future<AnnouncementLoginData?> googleLogin({
  required String? idToken,
  GeneralCallback<AnnouncementLoginData>? callback,
}) async {
  try {
    final Response<Map<String, dynamic>> response = await dio.post(
      '/oauth2/google/token',
      data: <String, String?>{
        'token': idToken,
        'fcmToken': fcmToken,
      },
    );
    final AnnouncementLoginData loginData =
        AnnouncementLoginData.fromJson(response.data!);
    setAuthorization(loginData.key);
    code = idToken;
    loginType = AnnouncementLoginType.google;
    if (callback != null) {
      callback.onSuccess(loginData);
    }
    return loginData;
  } on DioError catch (dioError) {
    if (callback == null) {
      rethrow;
    } else {
      if (dioError.isUnauthorized) {
        callback.onError(
          GeneralResponse(
            statusCode: 401,
            message: dioError.response?.data as String? ??
                ApLocalizations.current.unknownError,
          ),
        );
      }
      callback.onFailure(dioError);
    }
  }
  return null;
}