Skip to content

[google_sign_in] PR 3/4 Migrate ViewProvider and GID SDK wrappers from Objective-C to Swift - #12657

Open
victogomez-cs wants to merge 3 commits into
pr2/google-sign-in-ios-swift-pluginfrom
pr3/google-sign-in-ios-view-provider
Open

[google_sign_in] PR 3/4 Migrate ViewProvider and GID SDK wrappers from Objective-C to Swift#12657
victogomez-cs wants to merge 3 commits into
pr2/google-sign-in-ios-swift-pluginfrom
pr3/google-sign-in-ios-view-provider

Conversation

@victogomez-cs

@victogomez-cs victogomez-cs commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Migrates ViewProvider and the GID SDK wrappers from Objective-C to Swift. The plugin class from PR 2/4 now talks to Swift protocols instead of FSIViewProvider / FSIGIDSignIn.

The Swift GID API takes a non-optional presenter. Obj-C nonnull was not enforced at runtime, so a nil registrar view (headless / deallocated engine) was a silent no-op. Force-unwrapping that in Swift would crash. This PR completes with an NSError instead, mapped to a Flutter error like other unexpected failures.

Adds unit tests for the missing-presenter path (signIn / addScopes on iOS and macOS).

Bumps google_sign_in_ios to 6.3.4.

PR 3/4 of the Obj-C → Swift migration. Depends on PR 2/4 (plugin class). Continues flutter/flutter#119103

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 27, 2026
@victogomez-cs victogomez-cs added the triage-ios Should be looked at in iOS triage label Aug 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the ViewProvider and GID SDK wrappers from Objective-C to Swift within the iOS Google Sign-In plugin. It removes the legacy Objective-C files and introduces equivalent Swift protocols, wrappers, and view providers, while updating the plugin implementation and tests accordingly. The review feedback recommends avoiding force-unwrapping of non-optional properties (such as user, accessToken, and refreshToken) in the wrapper classes by implementing non-failable initializers for GIDGoogleUserWrapper and GIDTokenWrapper.

Comment on lines +124 to +126
var user: GIDGoogleUserProtocol {
return GIDGoogleUserWrapper(user: result.user)!
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since result.user is a non-optional GIDGoogleUser, we can avoid force-unwrapping here by providing a non-failable initializer in GIDGoogleUserWrapper.

Suggested change
var user: GIDGoogleUserProtocol {
return GIDGoogleUserWrapper(user: result.user)!
}
var user: GIDGoogleUserProtocol {
return GIDGoogleUserWrapper(user: result.user)
}
References
  1. Swift safety guidelines discourage the use of force-unwrapping (!) because it bypasses the compiler's type safety checks and can lead to runtime crashes. (link)

@victogomez-cs victogomez-cs Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed. That unwrap was only needed because GIDGoogleUserWrapper had a failable init. Added a non-failable init(user:) for the non-optional SDK value and dropped the !

Comment on lines +138 to +141
init?(user: GIDGoogleUser?) {
guard let user else { return nil }
self.user = user
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Provide a non-failable initializer for non-optional GIDGoogleUser instances, and make the failable initializer a convenience initializer. This allows wrapping non-optional users without force-unwrapping.

Suggested change
init?(user: GIDGoogleUser?) {
guard let user else { return nil }
self.user = user
}
init(user: GIDGoogleUser) {
self.user = user
}
convenience init?(user: GIDGoogleUser?) {
guard let user else { return nil }
self.init(user: user)
}
References
  1. Swift safety guidelines discourage the use of force-unwrapping (!) because it bypasses the compiler's type safety checks and can lead to runtime crashes. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. init(user: GIDGoogleUser) is the designated initializer, and convenience init?(user: GIDGoogleUser?) remains for the optional completion-handler values

Comment on lines +155 to +161
var accessToken: GIDTokenProtocol {
return GIDTokenWrapper(token: user.accessToken)!
}

var refreshToken: GIDTokenProtocol {
return GIDTokenWrapper(token: user.refreshToken)!
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since user.accessToken and user.refreshToken are non-optional, we can avoid force-unwrapping them by using a non-failable initializer in GIDTokenWrapper.

Suggested change
var accessToken: GIDTokenProtocol {
return GIDTokenWrapper(token: user.accessToken)!
}
var refreshToken: GIDTokenProtocol {
return GIDTokenWrapper(token: user.refreshToken)!
}
var accessToken: GIDTokenProtocol {
return GIDTokenWrapper(token: user.accessToken)
}
var refreshToken: GIDTokenProtocol {
return GIDTokenWrapper(token: user.refreshToken)
}
References
  1. Swift safety guidelines discourage the use of force-unwrapping (!) because it bypasses the compiler's type safety checks and can lead to runtime crashes. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed and fixed. accessToken and refreshToken are non-optional on GIDGoogleUser, so they now use the non-failable GIDTokenWrapper initializer. idToken is still optional, so that call site keeps the failable init

Comment on lines +241 to +244
init?(token: GIDToken?) {
guard let token else { return nil }
self.token = token
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Provide a non-failable initializer for non-optional GIDToken instances, and make the failable initializer a convenience initializer. This allows wrapping non-optional tokens without force-unwrapping.

Suggested change
init?(token: GIDToken?) {
guard let token else { return nil }
self.token = token
}
init(token: GIDToken) {
self.token = token
}
convenience init?(token: GIDToken?) {
guard let token else { return nil }
self.init(token: token)
}
References
  1. Swift safety guidelines discourage the use of force-unwrapping (!) because it bypasses the compiler's type safety checks and can lead to runtime crashes. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, same pattern as the user wrapper: non-failable init(token:) plus convenience init?(token:) for optional tokens

…ignInWrapper.

Introduces a new `requirePresenter` function to handle cases where the presenter is nil, preventing crashes and returning appropriate errors. Adds unit tests to verify behavior when signing in without a presenter, ensuring robust error reporting for the Google Sign-In process.
@victogomez-cs
victogomez-cs force-pushed the pr3/google-sign-in-ios-view-provider branch from 661e862 to 0e55e56 Compare August 27, 2026 17:37
@LouiseHsu
LouiseHsu requested a review from hellohuanlin August 27, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant