From 4d8e7ef73d6135a8cc9b5e53db1beb43977d44b0 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Mon, 24 Jun 2024 08:35:46 -0700 Subject: [PATCH] Add a note saying that we only create a single `Client`. (#1234) --- pkgs/flutter_http_example/lib/main.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/flutter_http_example/lib/main.dart b/pkgs/flutter_http_example/lib/main.dart index 548c3dee0a..afe8363029 100644 --- a/pkgs/flutter_http_example/lib/main.dart +++ b/pkgs/flutter_http_example/lib/main.dart @@ -15,6 +15,14 @@ import 'http_client_factory.dart' void main() { runApp(Provider( + // `Provider` calls its `create` argument once when a `Client` is + // first requested (through `BuildContext.read()`) 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()));