openFile method
Future<void>
openFile({
- required String assetFilePath,
- InAppBrowserClassOptions? options,
inherited
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.
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 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
.
Implementation
Future<void> openFile(
{required String assetFilePath,
InAppBrowserClassOptions? options}) async {
this.throwIfAlreadyOpened(message: 'Cannot open $assetFilePath!');
assert(assetFilePath.isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('id', () => id);
args.putIfAbsent('assetFilePath', () => assetFilePath);
args.putIfAbsent('options',
() => options?.toMap() ?? InAppBrowserClassOptions().toMap());
args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
args.putIfAbsent('windowId', () => windowId);
args.putIfAbsent('implementation', () => implementation.toValue());
args.putIfAbsent('initialUserScripts',
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
args.putIfAbsent(
'pullToRefreshOptions',
() =>
pullToRefreshController?.options.toMap() ??
PullToRefreshOptions(enabled: false).toMap());
await _sharedChannel.invokeMethod('open', args);
}