Skip to content

[google_font] Move the httpClient from a package level variable to the Config object#11027

Open
bramp wants to merge 2 commits intoflutter:mainfrom
bramp:config-http-client
Open

[google_font] Move the httpClient from a package level variable to the Config object#11027
bramp wants to merge 2 commits intoflutter:mainfrom
bramp:config-http-client

Conversation

@bramp
Copy link
Contributor

@bramp bramp commented Feb 14, 2026

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

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 3

…g object.

This allows the user to customise the httpClient as well as mock it out in tests.

Fixes #182429
@bramp bramp requested a review from Piinks as a code owner February 14, 2026 23:55
@github-actions github-actions bot added p: google_fonts triage-framework Should be looked at in framework triage labels Feb 14, 2026
@bramp bramp changed the title Move the httpClient from a package level variable to the Config object [google_font] Move the httpClient from a package level variable to the Config object Feb 14, 2026
Copy link

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

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 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.

Comment on lines 49 to 50
/// The HTTP client used to fetch fonts.
http.Client httpClient = http.Client();

Choose a reason for hiding this comment

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

high

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: google_fonts triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[google_fonts] Allow the HTTP client to be configured

1 participant