Skip to content

Commit ce17b4b

Browse files
authored
[google_sign_in_ios] Fix "callee requires a non-null parameter" analyzer warning (flutter#7513)
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 flutter#153587
1 parent 1d1fc4f commit ce17b4b

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

packages/google_sign_in/google_sign_in_ios/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 5.7.7
22

3+
* Fixes "callee requires a non-null parameter" analyzer warning.
34
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
45

56
## 5.7.6

packages/google_sign_in/google_sign_in_ios/darwin/Classes/FLTGoogleSignInPlugin.m

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ - (void)signInSilentlyWithCompletion:(nonnull void (^)(FSIUserData *_Nullable,
124124
FlutterError *_Nullable))completion {
125125
[self.signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser *_Nullable user,
126126
NSError *_Nullable error) {
127-
[self didSignInForUser:user withServerAuthCode:nil completion:completion error:error];
127+
if (user != nil) {
128+
[self didSignInForUser:user withServerAuthCode:nil completion:completion];
129+
} else {
130+
// Forward all errors and let Dart side decide how to handle.
131+
completion(nil, getFlutterError(error));
132+
}
128133
}];
129134
}
130135

@@ -152,17 +157,14 @@ - (void)signInWithCompletion:(nonnull void (^)(FSIUserData *_Nullable,
152157
[self signInWithHint:nil
153158
additionalScopes:self.requestedScopes.allObjects
154159
completion:^(GIDSignInResult *_Nullable signInResult, NSError *_Nullable error) {
155-
GIDGoogleUser *user;
156-
NSString *serverAuthCode;
157160
if (signInResult) {
158-
user = signInResult.user;
159-
serverAuthCode = signInResult.serverAuthCode;
161+
[self didSignInForUser:signInResult.user
162+
withServerAuthCode:signInResult.serverAuthCode
163+
completion:completion];
164+
} else {
165+
// Forward all errors and let Dart side decide how to handle.
166+
completion(nil, getFlutterError(error));
160167
}
161-
162-
[self didSignInForUser:user
163-
withServerAuthCode:serverAuthCode
164-
completion:completion
165-
error:error];
166168
}];
167169
} @catch (NSException *e) {
168170
completion(nil, [FlutterError errorWithCode:@"google_sign_in" message:e.reason details:e.name]);
@@ -291,30 +293,21 @@ - (GIDConfiguration *)configurationWithClientIdentifier:(NSString *)runtimeClien
291293

292294
- (void)didSignInForUser:(GIDGoogleUser *)user
293295
withServerAuthCode:(NSString *_Nullable)serverAuthCode
294-
completion:(nonnull void (^)(FSIUserData *_Nullable,
295-
FlutterError *_Nullable))completion
296-
error:(NSError *)error {
297-
if (error != nil) {
298-
// Forward all errors and let Dart side decide how to handle.
299-
completion(nil, getFlutterError(error));
300-
} else {
301-
NSURL *photoUrl;
302-
if (user.profile.hasImage) {
303-
// Placeholder that will be replaced by on the Dart side based on screen size.
304-
photoUrl = [user.profile imageURLWithDimension:1337];
305-
}
306-
NSString *idToken;
307-
if (user.idToken) {
308-
idToken = user.idToken.tokenString;
309-
}
310-
completion([FSIUserData makeWithDisplayName:user.profile.name
311-
email:user.profile.email
312-
userId:user.userID
313-
photoUrl:[photoUrl absoluteString]
314-
serverAuthCode:serverAuthCode
315-
idToken:idToken],
316-
nil);
296+
completion:
297+
(nonnull void (^)(FSIUserData *_Nullable, FlutterError *_Nullable))completion {
298+
NSURL *photoUrl;
299+
if (user.profile.hasImage) {
300+
// Placeholder that will be replaced by on the Dart side based on screen size.
301+
photoUrl = [user.profile imageURLWithDimension:1337];
317302
}
303+
304+
completion([FSIUserData makeWithDisplayName:user.profile.name
305+
email:user.profile.email
306+
userId:user.userID
307+
photoUrl:photoUrl.absoluteString
308+
serverAuthCode:serverAuthCode
309+
idToken:user.idToken.tokenString],
310+
nil);
318311
}
319312

320313
#if TARGET_OS_IOS

packages/google_sign_in/google_sign_in_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_sign_in_ios
22
description: iOS implementation of the google_sign_in plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
5-
version: 5.7.6
5+
version: 5.7.7
66

77
environment:
88
sdk: ^3.3.0

0 commit comments

Comments
 (0)