From ce17b4b2f692d33250a0b547dffab00a973d6209 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 27 Aug 2024 12:43:19 -0700 Subject: [PATCH] [google_sign_in_ios] Fix "callee requires a non-null parameter" analyzer warning (#7513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The normal Cocoa pattern is to check a result, and only if it's nil then do something with the error. https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html > Important: Success or failure is indicated by the return value of the method. Although Cocoa methods that indirectly return error objects in the Cocoa error domain are guaranteed to return such objects if the method indicates failure by directly returning nil or NO, you should always check that the return value is nil or NO before attempting to do anything with the NSError object. Use this pattern with the result and error from the sign in completion block. This means `-didSignInForUser` is only called for non-nil users (the possibility of a nullable parameter was kicking off the analyzer warning). ![Screenshot 2024-08-26 at 4 24 04 PM](https://github.com/user-attachments/assets/56937344-ab54-4ac6-9f8c-7fdb84f9567a) Fixes https://github.com/flutter/flutter/issues/153587 --- .../google_sign_in_ios/CHANGELOG.md | 3 +- .../darwin/Classes/FLTGoogleSignInPlugin.m | 59 ++++++++----------- .../google_sign_in_ios/pubspec.yaml | 2 +- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md b/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md index 88ed91b01746..285af4a4bc26 100644 --- a/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 5.7.7 +* Fixes "callee requires a non-null parameter" analyzer warning. * Updates minimum supported SDK version to Flutter 3.19/Dart 3.3. ## 5.7.6 diff --git a/packages/google_sign_in/google_sign_in_ios/darwin/Classes/FLTGoogleSignInPlugin.m b/packages/google_sign_in/google_sign_in_ios/darwin/Classes/FLTGoogleSignInPlugin.m index 99ee0348f518..7ba4db916089 100644 --- a/packages/google_sign_in/google_sign_in_ios/darwin/Classes/FLTGoogleSignInPlugin.m +++ b/packages/google_sign_in/google_sign_in_ios/darwin/Classes/FLTGoogleSignInPlugin.m @@ -124,7 +124,12 @@ - (void)signInSilentlyWithCompletion:(nonnull void (^)(FSIUserData *_Nullable, FlutterError *_Nullable))completion { [self.signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser *_Nullable user, NSError *_Nullable error) { - [self didSignInForUser:user withServerAuthCode:nil completion:completion error:error]; + if (user != nil) { + [self didSignInForUser:user withServerAuthCode:nil completion:completion]; + } else { + // Forward all errors and let Dart side decide how to handle. + completion(nil, getFlutterError(error)); + } }]; } @@ -152,17 +157,14 @@ - (void)signInWithCompletion:(nonnull void (^)(FSIUserData *_Nullable, [self signInWithHint:nil additionalScopes:self.requestedScopes.allObjects completion:^(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error) { - GIDGoogleUser *user; - NSString *serverAuthCode; if (signInResult) { - user = signInResult.user; - serverAuthCode = signInResult.serverAuthCode; + [self didSignInForUser:signInResult.user + withServerAuthCode:signInResult.serverAuthCode + completion:completion]; + } else { + // Forward all errors and let Dart side decide how to handle. + completion(nil, getFlutterError(error)); } - - [self didSignInForUser:user - withServerAuthCode:serverAuthCode - completion:completion - error:error]; }]; } @catch (NSException *e) { completion(nil, [FlutterError errorWithCode:@"google_sign_in" message:e.reason details:e.name]); @@ -291,30 +293,21 @@ - (GIDConfiguration *)configurationWithClientIdentifier:(NSString *)runtimeClien - (void)didSignInForUser:(GIDGoogleUser *)user withServerAuthCode:(NSString *_Nullable)serverAuthCode - completion:(nonnull void (^)(FSIUserData *_Nullable, - FlutterError *_Nullable))completion - error:(NSError *)error { - if (error != nil) { - // Forward all errors and let Dart side decide how to handle. - completion(nil, getFlutterError(error)); - } else { - NSURL *photoUrl; - if (user.profile.hasImage) { - // Placeholder that will be replaced by on the Dart side based on screen size. - photoUrl = [user.profile imageURLWithDimension:1337]; - } - NSString *idToken; - if (user.idToken) { - idToken = user.idToken.tokenString; - } - completion([FSIUserData makeWithDisplayName:user.profile.name - email:user.profile.email - userId:user.userID - photoUrl:[photoUrl absoluteString] - serverAuthCode:serverAuthCode - idToken:idToken], - nil); + completion: + (nonnull void (^)(FSIUserData *_Nullable, FlutterError *_Nullable))completion { + NSURL *photoUrl; + if (user.profile.hasImage) { + // Placeholder that will be replaced by on the Dart side based on screen size. + photoUrl = [user.profile imageURLWithDimension:1337]; } + + completion([FSIUserData makeWithDisplayName:user.profile.name + email:user.profile.email + userId:user.userID + photoUrl:photoUrl.absoluteString + serverAuthCode:serverAuthCode + idToken:user.idToken.tokenString], + nil); } #if TARGET_OS_IOS diff --git a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml index c86af4d3f0e0..2bdbc6eec3b7 100644 --- a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in_ios description: iOS implementation of the google_sign_in plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 5.7.6 +version: 5.7.7 environment: sdk: ^3.3.0