fetch function

Future<Response> fetch(
  1. Object resource, {
  2. String? method,
  3. Object? headers,
  4. Object? body,
  5. RequestMode? mode,
  6. RequestCredentials? credentials,
  7. RequestCache? cache,
  8. RequestRedirect? redirect,
  9. String? referrer,
  10. ReferrerPolicy? referrerPolicy,
  11. String? integrity,
  12. bool? keepalive,
  13. RequestDestination? destination,
})

The fetch() method starts the process of fetching a resource from the network, returning a promise which is fulfilled once the response is available.

MDN Reference

Implementation

Future<Response> fetch(
  Object resource, {
  String? method,
  Object? headers,
  Object? body,
  RequestMode? mode,
  RequestCredentials? credentials,
  RequestCache? cache,
  RequestRedirect? redirect,
  String? referrer,
  ReferrerPolicy? referrerPolicy,
  String? integrity,
  bool? keepalive,
  RequestDestination? destination,
}) {
  final request = Request(
    resource,
    method: method,
    headers: headers,
    body: body,
    mode: mode,
    credentials: credentials,
    cache: cache,
    redirect: redirect,
    referrer: referrer,
    referrerPolicy: referrerPolicy,
    integrity: integrity,
    destination: destination,
  );

  return _globalClient.send(request, keepalive: keepalive ?? false);
}