Skip to content
WebView AllWebView All
Documentation for version 1.2.x; select latest for up-to-date APIs.

Files, Assets, HTML

await controller.loadFile('/Users/me/Documents/page.html');

Platform behavior:

PlatformBehavior
AndroidUses file URL loading. AndroidLoadFileParams can add headers.
iOS/macOSUses WebKit local file loading. WebKitLoadFileParams controls read access scope.
WindowsMaps the file’s directory to a virtual HTTPS host.
LinuxLoads the absolute file through WebKitGTK.
OHOSEnables file access and loads the file URL.
WebUnsupported; browsers do not allow arbitrary file reads from a hosted app.
await controller.platform.loadFileWithParams(
AndroidLoadFileParams(
absoluteFilePath: '/sdcard/Download/page.html',
headers: const <String, String>{'X-Source': 'app'},
),
);
await controller.platform.loadFileWithParams(
WebKitLoadFileParams(
absoluteFilePath: '/Users/me/site/index.html',
readAccessPath: '/Users/me/site',
),
);

readAccessPath must include any images, scripts, and styles referenced by the HTML file.

Declare the asset:

flutter:
assets:
- assets/help/index.html

Load it:

await controller.loadFlutterAsset('assets/help/index.html');

On Windows, the implementation maps the asset directory to an internal HTTPS host. On web, it resolves the asset under the app’s generated assets/ path.

await controller.loadHtmlString(
'<html><body><a href="details.html">Details</a></body></html>',
baseUrl: 'https://docs.example.com/help/',
);

Use baseUrl when the document contains relative URLs.

await controller.loadRequest(
Uri.parse('https://api.example.com/form'),
method: LoadRequestMethod.post,
headers: const <String, String>{'Content-Type': 'application/json'},
body: Uint8List.fromList(utf8.encode('{"ok":true}')),
);

Check platform support before relying on custom requests:

PlatformNotes
AndroidPOST with custom headers is not supported by Android WebView postUrl.
OHOSPOST with custom headers is not supported by ArkWeb postUrl; webview_all_ohos throws UnsupportedError.
WebNon-simple requests use fetch and require CORS approval from the server.
Windows/Linux/iOS/macOSSupport method, headers, and body through native request APIs.

Recommended Fallback for Unsupported POST Headers

Section titled “Recommended Fallback for Unsupported POST Headers”

When a platform cannot submit a POST with custom headers directly, send the request with your app’s HTTP client and load the resulting HTML:

final response = await http.post(
Uri.parse('https://api.example.com/form'),
headers: const <String, String>{'Authorization': 'Bearer token'},
body: '{"ok":true}',
);
await controller.loadHtmlString(
response.body,
baseUrl: 'https://api.example.com/form',
);

This fallback is appropriate for HTML responses. It is not equivalent to browser navigation for cookies, redirects, service workers, or streaming responses.