openFile method
Future<void>
openFile({
- required String assetFilePath,
- @Deprecated('Use settings instead') InAppBrowserClassOptions? options,
- InAppBrowserClassSettings? settings,
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.
settings
: Settings for the InAppBrowser.
Supported Platforms/Implementations:
- Android native WebView
- iOS
- MacOS
Implementation
Future<void> openFile(
{required String assetFilePath,
// ignore: deprecated_member_use_from_same_package
@Deprecated('Use settings instead') InAppBrowserClassOptions? options,
InAppBrowserClassSettings? settings}) async {
this.throwIfAlreadyOpened(message: 'Cannot open $assetFilePath!');
assert(assetFilePath.isNotEmpty);
var initialSettings = settings?.toMap() ??
options?.toMap() ??
InAppBrowserClassSettings().toMap();
Map<String, dynamic> pullToRefreshSettings =
pullToRefreshController?.settings.toMap() ??
// ignore: deprecated_member_use_from_same_package
pullToRefreshController?.options.toMap() ??
PullToRefreshSettings(enabled: false).toMap();
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('id', () => id);
args.putIfAbsent('assetFilePath', () => assetFilePath);
args.putIfAbsent('settings', () => initialSettings);
args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
args.putIfAbsent('windowId', () => windowId);
args.putIfAbsent('implementation', () => implementation.toNativeValue());
args.putIfAbsent('initialUserScripts',
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
args.putIfAbsent('pullToRefreshSettings', () => pullToRefreshSettings);
await _sharedChannel.invokeMethod('open', args);
}