Skip to content

Commit 4d8e7ef

Browse files
authored
Add a note saying that we only create a single Client. (#1234)
1 parent 8c325b9 commit 4d8e7ef

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkgs/flutter_http_example/lib/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import 'http_client_factory.dart'
1515

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

0 commit comments

Comments
 (0)