Skip to content

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

Open
bramp wants to merge 3 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 3 commits intoflutter:mainfrom
bramp:config-http-client

Conversation

@bramp
Copy link
Copy Markdown
Contributor

@bramp bramp commented Feb 14, 2026

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

@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
Copy Markdown

@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();
Copy link
Copy Markdown

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.

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.

Absolutely right - however before my change, this httpClient was being created globally without a way to dispose of it. So I've not made the situation worse.

I'll happily add a dispose method if folks want that - but since GoogleFonts isn't explicitly init'd I'm not sure a dispose makes sense. Because then we'd have to deal with folks trying to use GoogleFronts after it's been disposed.

Copy link
Copy Markdown
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@Piinks
Copy link
Copy Markdown
Contributor

Piinks commented Mar 17, 2026

Hey @bramp is this still a change you would like to work on?

@bramp bramp force-pushed the config-http-client branch from 5d6b71a to 02c4076 Compare April 12, 2026 16:52
@bramp
Copy link
Copy Markdown
Contributor Author

bramp commented Apr 12, 2026

Sorry for my slow turn around. Ok I've replied to all comments - and pushed updates for changelog/version bump. The only linger decision is in #11027 (comment)

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

2 participants