Files, Assets, HTML
Local Files
Section titled “Local Files”await controller.loadFile('/Users/me/Documents/page.html');Platform behavior:
| Platform | Behavior |
|---|---|
| Android | Uses file URL loading. AndroidLoadFileParams can add headers. |
| iOS/macOS | Uses WebKit local file loading. WebKitLoadFileParams controls read access scope. |
| Windows | Maps the file’s directory to a virtual HTTPS host. |
| Linux | Loads the absolute file through WebKitGTK. |
| OHOS | Enables file access and loads the file URL. |
| Web | Unsupported; browsers do not allow arbitrary file reads from a hosted app. |
Android File Headers
Section titled “Android File Headers”await controller.platform.loadFileWithParams( AndroidLoadFileParams( absoluteFilePath: '/sdcard/Download/page.html', headers: const <String, String>{'X-Source': 'app'}, ),);WebKit Read Access
Section titled “WebKit Read Access”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.
Flutter Assets
Section titled “Flutter Assets”Declare the asset:
flutter: assets: - assets/help/index.htmlLoad it:
await controller.loadFlutterAsset('assets/help/index.html');On Windows, each controller maps the canonical asset directory to a private randomized HTTPS host with cross-origin access denied. Mappings are replaced or cleared as navigation changes. Linux requires absolute file paths and canonicalizes them before loading. Both implementations reject traversal and symlink escapes outside the Flutter asset bundle. On web, assets resolve under the app’s generated assets/ path.
Inline HTML
Section titled “Inline HTML”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.
Custom Requests
Section titled “Custom Requests”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:
| Platform | Notes |
|---|---|
| Android | POST with custom headers is not supported by Android WebView postUrl. |
| OHOS | POST with custom headers is not supported by ArkWeb postUrl; webview_all_ohos throws UnsupportedError. |
| Web | Non-simple requests use fetch, require CORS approval, preserve binary response bytes, and use the final redirect URL as the logical URL. |
| Windows/Linux/iOS/macOS | Support 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.