Skip to content

[google_sign_in_ios] Fix "callee requires a non-null parameter" analyzer warning #7513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/google_sign_in/google_sign_in_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}];
}

Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
}
Comment on lines -306 to -309
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, if user.idToken is nil then user.idToken.tokenString will also be nil. This is another normal Cocoa pattern, don't check nils since calling a selector (method) on nil will harmlessly also return nil.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swap to dot-notation because absoluteString is a property. This is just a convention, there's no functional difference.
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html

serverAuthCode:serverAuthCode
idToken:user.idToken.tokenString],
nil);
}

#if TARGET_OS_IOS
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down