openFile method Null safety

Future<void> openFile(
  1. {required String assetFilePath,
  2. InAppBrowserClassOptions? options}

Opens the InAppBrowser instance with the given assetFilePath file.

options: Options for the InAppBrowser.

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.

 # 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/index.html
   - assets/css/
   - assets/images/


Example of a main.dart file:

inAppBrowser.openFile(assetFilePath: "assets/index.html");

headers: The additional headers to be used in the HTTP request for this URL, specified as a map from name to value.

options: Options for the InAppBrowser.


Future<void> openFile(
    {required String assetFilePath,
    InAppBrowserClassOptions? options}) async {
  this.throwIfAlreadyOpened(message: 'Cannot open $assetFilePath!');

  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('id', () => id);
  args.putIfAbsent('assetFilePath', () => assetFilePath);
      () => options?.toMap() ?? InAppBrowserClassOptions().toMap());
  args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
  args.putIfAbsent('windowId', () => windowId);
      () => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
      () =>
          pullToRefreshController?.options.toMap() ??
          PullToRefreshOptions(enabled: false).toMap());
  await _sharedChannel.invokeMethod('open', args);