loadRequest method

  1. @override
Future<void> loadRequest(
  1. WebViewRequest request
)

When making a POST request, headers are ignored. As a workaround, make the request manually and load the response data using loadHTMLString.

Implementation

@override
Future<void> loadRequest(
  WebViewRequest request,
) async {
  if (!request.uri.hasScheme) {
    throw ArgumentError('WebViewRequest#uri is required to have a scheme.');
  }
  switch (request.method) {
    case WebViewRequestMethod.get:
      return webView.loadUrl(request.uri.toString(), request.headers);
    case WebViewRequestMethod.post:
      return webView.postUrl(
          request.uri.toString(), request.body ?? Uint8List(0));
    default:
      throw UnimplementedError(
        'This version of webview_android_widget currently has no implementation for HTTP method ${request.method.serialize()} in loadRequest.',
      );
  }
}