[google_sign_in_web]Fix renderButton stuck on "Getting ready" for Web (Future<void> issue)#11081
[google_sign_in_web]Fix renderButton stuck on "Getting ready" for Web (Future<void> issue)#11081puneetkukreja98 wants to merge 3 commits intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses a bug in renderButton on the web, where the widget would remain in a "Getting ready" state. The change correctly updates the condition within the FutureBuilder to check snapshot.connectionState == ConnectionState.done instead of snapshot.hasData, which is the proper way to handle a Future<void>. I've included a suggestion to enhance robustness by also handling potential error states within the FutureBuilder.
| future: _initialized, | ||
| builder: (BuildContext context, AsyncSnapshot<void> snapshot) { | ||
| if (snapshot.hasData) { | ||
| if (snapshot.connectionState == ConnectionState.done) { |
There was a problem hiding this comment.
While this change correctly handles a completed Future<void>, it's best practice to also handle potential errors. If the _initialized future completes with an error, snapshot.hasError will be true, and the widget should display an error state instead of attempting to render the button. Consider handling the error case explicitly for better robustness.
For example:
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.hasError) {
// In case of error, show an empty box or an error message.
// Consider logging the error as well.
return const SizedBox.shrink();
}
if (snapshot.connectionState == ConnectionState.done) {
return FlexHtmlElementView(
viewType: 'gsi_login_button',
onElementCreated: (Object element) {
_gisSdkClient.renderButton(element, config);
},
);
}
return const Text('Getting ready');
},|
The current published version is 1.1.1. |
This needs the changelog and version steps in the checklist as part of the PR for that to happen. |
mdebbar
left a comment
There was a problem hiding this comment.
Thanks for the quick fix @puneetkukreja98!
In addition to what @stuartmorgan-g said, would you mind also adding a test to protect us from the same issue in the future?
|
Thanks for the review @stuartmorgan-g & @mdebbar . |
07d7191 to
af83e31
Compare
Previously, renderButton() used
snapshot.hasData, but the Future completes with null on web.This caused the button to never render, always showing "Getting ready".
Replaced with
snapshot.connectionState == ConnectionState.doneto fix.Fixes: flutter/flutter#182633
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).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-assistbot 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
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 ↩3