Skip to content

Commit 8d89385

Browse files
authored
Make it more clear to using use runWithClient in the Dart SDK. (#1250)
1 parent 321362a commit 8d89385

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pkgs/http/README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,22 @@ void main() {
249249
}
250250
```
251251

252-
In Flutter, you can use a one of many
252+
When using the Flutter SDK, you can use a one of many
253253
[state management approaches][flutterstatemanagement].
254254

255-
If you depend on code that uses top-level functions (e.g. `http.post`) or
256-
calls the [`Client()`][clientconstructor] constructor, then you can use
257-
[`runWithClient`][runwithclient] to ensure that the correct
258-
`Client` is used. When an [Isolate][isolate] is spawned, it does not inherit
259-
any variables from the calling Zone, so `runWithClient` needs to be used in
260-
each Isolate that uses `package:http`.
255+
> [!TIP]
256+
> [The Flutter HTTP example application][flutterhttpexample] demonstrates
257+
> how to make the configured [`Client`][client] available using
258+
> [`package:provider`][provider] and
259+
> [`package:http_image_provider`][http_image_provider].
260+
261+
When using the Dart SDK, you can use [`runWithClient`][runwithclient] to
262+
ensure that the correct [`Client`][client] is used when explicit argument
263+
passing is not an option. For example, if you depend on code that uses
264+
top-level functions (e.g. `http.post`) or calls the
265+
[`Client()`][clientconstructor] constructor. When an [Isolate][isolate] is
266+
spawned, it does not inherit any variables from the calling Zone, so
267+
`runWithClient` needs to be used in each Isolate that uses `package:http`.
261268

262269
You can ensure that only the `Client` that you have explicitly configured is
263270
used by defining `no_default_http_client=true` in the environment. This will
@@ -269,11 +276,6 @@ $ flutter build appbundle --dart-define=no_default_http_client=true ...
269276
$ dart compile exe --define=no_default_http_client=true ...
270277
```
271278

272-
> [!TIP]
273-
> [The Flutter HTTP example application][flutterhttpexample] demonstrates
274-
> how to make the configured [`Client`][client] available using
275-
> [`package:provider`][provider] and [`package:http_image_provider`][http_image_provider].
276-
277279
[browserclient]: https://pub.dev/documentation/http/latest/browser_client/BrowserClient-class.html
278280
[client]: https://pub.dev/documentation/http/latest/http/Client-class.html
279281
[clientconstructor]: https://pub.dev/documentation/http/latest/http/Client/Client.html

0 commit comments

Comments
 (0)