Skip to content

Commit

Permalink
Add a note saying that we only create a single Client. (#1234)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Jun 24, 2024
1 parent 8c325b9 commit 4d8e7ef
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 4d8e7ef

Please sign in to comment.