[google_font] Move the httpClient from a package level variable to the Config object#11027
[google_font] Move the httpClient from a package level variable to the Config object#11027bramp wants to merge 2 commits intoflutter:mainfrom
Conversation
…g object. This allows the user to customise the httpClient as well as mock it out in tests. Fixes #182429
There was a problem hiding this comment.
Code Review
This pull request refactors the httpClient to be part of the GoogleFonts.config object. This is a good change that improves testability and allows users to provide a custom HTTP client. However, I've identified a potential resource leak issue with the default http.Client instance not being closed. My review includes a comment with details on this issue.
| /// The HTTP client used to fetch fonts. | ||
| http.Client httpClient = http.Client(); |
There was a problem hiding this comment.
The http.Client should be closed when it's no longer needed to release underlying resources. The current implementation creates a default client but never closes it, which can lead to resource leaks.
Please consider how the client's lifecycle will be managed. For example, you could add a static GoogleFonts.dispose() method that closes the default client. You should also document that if a user supplies their own httpClient, they are responsible for closing it.
In progress: I have not written changelog/documentation updates. I want to get early feedback / validation on this idea before I do the remaining work.
Move the httpClient from a package level variable, to be on the Config object
This allows the user to customise the httpClient as well as mock it out in tests.
Fixes #182429
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