loadRequest method

  1. @override
Future<void> loadRequest(
  1. LoadRequestParams params
)

Makes a specific HTTP request ands loads the response in the webview.

WebViewRequest.method must be one of the supported HTTP methods in WebViewRequestMethod.

If WebViewRequest.headers is not empty, its key-value pairs will be added as the headers for the request.

If WebViewRequest.body is not null, it will be added as the body for the request.

Throws an ArgumentError if WebViewRequest.uri has empty scheme.

Implementation

@override
Future<void> loadRequest(
  LoadRequestParams params,
) {
  if (!params.uri.hasScheme) {
    throw ArgumentError('WebViewRequest#uri is required to have a scheme.');
  }
  switch (params.method) {
    case LoadRequestMethod.get:
      return _webView.loadUrl(params.uri.toString(), params.headers);
    case LoadRequestMethod.post:
      return _webView.postUrl(
          params.uri.toString(), params.body ?? Uint8List(0));
  }
  // The enum comes from a different package, which could get a new value at
  // any time, so a fallback case is necessary. Since there is no reasonable
  // default behavior, throw to alert the client that they need an updated
  // version. This is deliberately outside the switch rather than a `default`
  // so that the linter will flag the switch as needing an update.
  // ignore: dead_code
  throw UnimplementedError(
      'This version of `AndroidWebViewController` currently has no '
      'implementation for HTTP method ${params.method.serialize()} in '
      'loadRequest.');
}