Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a note saying that we only create a single Client. #1234

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkgs/flutter_http_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import 'http_client_factory.dart'

void main() {
runApp(Provider<Client>(
// `Provider` calls its `create` argument once when a `Client` is
// first requested (through `BuildContext.read<Client>()`) and uses that
// same instance for all future requests.
//
// Reusing the same `Client` may:
// - reduce memory usage
// - allow caching of fetched URLs
// - allow connections to be persisted
create: (_) => http_factory.httpClient(),
child: const BookSearchApp(),
dispose: (_, client) => client.close()));
Expand Down