loadFile method

  1. @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebView.loadUrl', apiUrl: 'https://developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String)'), IOSPlatform(apiName: 'WKWebView.load', apiUrl: 'https://developer.apple.com/documentation/webkit/wkwebview/1414954-load'), MacOSPlatform(apiName: 'WKWebView.load', apiUrl: 'https://developer.apple.com/documentation/webkit/wkwebview/1414954-load'), WebPlatform(), WindowsPlatform(apiName: 'ICoreWebView2.Navigate', apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2210.55#navigate'), LinuxPlatform(apiName: 'webkit_web_view_load_uri', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.WebView.load_uri.html')])
Future<void> loadFile({
  1. required String assetFilePath,
})

Loads the given assetFilePath.

To be able to load your local files (assets, js, css, etc.), you need to add them in the assets section of the pubspec.yaml file, otherwise they cannot be found!

Example of a pubspec.yaml file:

...

# The following section is specific to Flutter.
flutter:

 # The following line ensures that the Material Icons font is
 # included with your application, so that you can use the icons in
 # the material Icons class.
 uses-material-design: true

 assets:
   - assets/index.html
   - assets/css/
   - assets/images/

...

Example:

...
controller.loadFile(assetFilePath: "assets/index.html");
...

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • assetFilePath: all platforms

Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.

Implementation

@SupportedPlatforms(
  platforms: [
    AndroidPlatform(
      apiName: 'WebView.loadUrl',
      apiUrl:
          'https://developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String)',
    ),
    IOSPlatform(
      apiName: 'WKWebView.load',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkwebview/1414954-load',
    ),
    MacOSPlatform(
      apiName: 'WKWebView.load',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkwebview/1414954-load',
    ),
    WebPlatform(),
    WindowsPlatform(
      apiName: 'ICoreWebView2.Navigate',
      apiUrl:
          'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2?view=webview2-1.0.2210.55#navigate',
    ),
    LinuxPlatform(
      apiName: 'webkit_web_view_load_uri',
      apiUrl:
          'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.WebView.load_uri.html',
    ),
  ],
)
Future<void> loadFile({required String assetFilePath}) {
  throw UnimplementedError(
    '${PlatformInAppWebViewControllerMethod.loadFile.name} is not implemented on the current platform',
  );
}