A Flutter plugin that allows you to add an inline webview or open an in-app browser window.
A Flutter plugin that allows you to add an inline webview or open an in-app browser window.
### Requirements
### Requirements
- Dart sdk: ">=2.1.0-dev.7.1 <3.0.0"
- Flutter: ">=0.10.1 <2.0.0"
- Dart sdk: ">=2.0.0-dev.68.0 <3.0.0"
- Flutter: ">=1.9.1+hotfix.5 <2.0.0"
- Android: `minSdkVersion 17`
- Android: `minSdkVersion 17`
- iOS: `--ios-language swift`
- iOS: `--ios-language swift`
### Note for Android
### Note for Android
During the build, if Android fails with `Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library`, it means that you need to update the `minSdkVersion` of your `build.gradle` file to at least `17`.
During the build, if Android fails with `Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library`, it means that you need to update the `minSdkVersion` of your `build.gradle` file to at least `17`.
Because of [Flutter AndroidX compatibility](https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility), the latest version that doesn't use `AndroidX` is `0.6.0`.
Because of [Flutter AndroidX compatibility](https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility), the latest version that doesn't use `AndroidX` is `0.6.0`.
### IMPORTANT Note for iOS
### IMPORTANT Note for iOS
If you are starting a new fresh app, you need to create the Flutter App with `flutter create -i swift` (see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message:
If you are starting a new fresh app, you need to create the Flutter App with `flutter create -i swift` (see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message:
```
```
=== BUILD TARGET flutter_inappbrowser OF PROJECT Pods WITH CONFIGURATION Debug ===
=== BUILD TARGET flutter_inappbrowser OF PROJECT Pods WITH CONFIGURATION Debug ===
...
@@ -54,23 +57,54 @@ For help getting started with Flutter, view our online
...
@@ -54,23 +57,54 @@ For help getting started with Flutter, view our online
For help on editing plugin code, view the [documentation](https://flutter.io/developing-packages/#edit-plugin-package).
For help on editing plugin code, view the [documentation](https://flutter.io/developing-packages/#edit-plugin-package).
## Installation
## Installation
First, add `flutter_inappbrowser` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/).
First, add `flutter_inappbrowser` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/).
## Usage
## Usage
Classes:
Classes:
-[InAppWebView](#inappwebview-class): Flutter Widget for adding an **inline native WebView** integrated into the flutter widget tree. To use `InAppWebView` class on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` and the value `YES`.
-[InAppWebView](#inappwebview-class): Flutter Widget for adding an **inline native WebView** integrated into the flutter widget tree. To use `InAppWebView` class on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` and the value `YES`.
-[InAppBrowser](#inappbrowser-class): In-App Browser using native WebView.
-[InAppBrowser](#inappbrowser-class): In-App Browser using native WebView.
-[ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS.
-[ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS.
-[InAppLocalhostServer](#inapplocalhostserver-class): This class allows you to create a simple server on `http://localhost:[port]/`. The default `port` value is `8080`.
-[InAppLocalhostServer](#inapplocalhostserver-class): This class allows you to create a simple server on `http://localhost:[port]/`. The default `port` value is `8080`.
-[CookieManager](#cookiemanager-class): Manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+.
-[CookieManager](#cookiemanager-class): This class implements a singleton object (shared instance) which manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+.
-[HttpAuthCredentialDatabase](#httpauthcredentialdatabase-class): This class implements a singleton object (shared instance) which manages the shared HTTP auth credentials cache.
## API Reference
See the online [API Reference](https://pub.dartlang.org/documentation/flutter_inappbrowser/latest/) to get the full documentation.
### Load a file inside `assets` folder
See the online [docs](https://pub.dartlang.org/documentation/flutter_inappbrowser/latest/) to get the full documentation.
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:
```yaml
...
# 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/
...
```
### `InAppWebView` class
### `InAppWebView` class
Flutter Widget for adding an **inline native WebView** integrated into the flutter widget tree.
Flutter Widget for adding an **inline native WebView** integrated into the flutter widget tree.
The plugin relies on Flutter's mechanism (in developers preview) for embedding Android and iOS native views: [AndroidView](https://docs.flutter.io/flutter/widgets/AndroidView-class.html) and [UiKitView](https://docs.flutter.io/flutter/widgets/UiKitView-class.html).
The plugin relies on Flutter's mechanism (in developers preview) for embedding Android and iOS native views: [AndroidView](https://docs.flutter.io/flutter/widgets/AndroidView-class.html) and [UiKitView](https://docs.flutter.io/flutter/widgets/UiKitView-class.html).
Known issues are tagged with the [platform-views](https://github.com/flutter/flutter/labels/a%3A%20platform-views) label in the [Flutter official repo](https://github.com/flutter/flutter).
Known issues are tagged with the [platform-views](https://github.com/flutter/flutter/labels/a%3A%20platform-views) label in the [Flutter official repo](https://github.com/flutter/flutter).
Keyboard support within webviews is also experimental.
To use `InAppWebView` class on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` and the value `YES`.
To use `InAppWebView` class on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` and the value `YES`.
...
@@ -111,96 +145,84 @@ class _MyAppState extends State<MyApp> {
...
@@ -111,96 +145,84 @@ class _MyAppState extends State<MyApp> {
Initial asset file that will be loaded. See `InAppWebView.loadFile()` for explanation.
*`getProgress`: Gets the progress for the current page. The progress value is between 0 and 100.
*`getHtml`: Gets the content html of the page.
#### InAppWebView.initialData
*`getFavicons`: Gets the list of all favicons for the current page.
Initial `InAppWebViewInitialData` that will be loaded.
*`loadUrl({@required String url, Map<String, String> headers = const {}})`: Loads the given url with optional headers specified as a map from name to value.
*`postUrl({@required String url, @required Uint8List postData})`: Loads the given url with postData using `POST` method into this WebView.
#### InAppWebView.initialHeaders
*`loadData({@required String data, String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank"})`: Loads the given data into this WebView.
Initial headers that will be used.
*`loadFile({@required String assetFilePath, Map<String, String> headers = const {}})`: Loads the given `assetFilePath` with optional headers specified as a map from name to value.
*`reload`: Reloads the WebView.
#### InAppWebView.initialOptions
*`goBack`: Goes back in the history of the WebView.
Initial options that will be used.
*`canGoBack`: Returns a boolean value indicating whether the WebView can move backward.
*`goForward`: Goes forward in the history of the WebView.
All platforms support:
*`canGoForward`: Returns a boolean value indicating whether the WebView can move forward.
- __useShouldOverrideUrlLoading__: Set to `true` to be able to listen at the `shouldOverrideUrlLoading()` event. The default value is `false`.
*`goBackOrForward({@required int steps})`: Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.
- __useOnLoadResource__: Set to `true` to be able to listen at the `onLoadResource()` event. The default value is `false`.
*`canGoBackOrForward({@required int steps})`: Returns a boolean value indicating whether the WebView can go back or forward the given number of steps. Steps is negative if backward and positive if forward.
- __clearCache__: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
*`goTo({@required WebHistoryItem historyItem})`: Navigates to a `WebHistoryItem` from the back-forward `WebHistory.list` and sets it as the current item.
- __userAgent__: Set the custom WebView's user-agent.
*`isLoading`: Check if the WebView instance is in a loading state.
- __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`.
*`stopLoading`: Stops the WebView from loading.
- __javaScriptCanOpenWindowsAutomatically__: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
*`evaluateJavascript({@required String source})`: Evaluates JavaScript code into the WebView and returns the result of the evaluation.
- __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
*`injectJavascriptFileFromUrl({@required String urlFile})`: Injects an external JavaScript file into the WebView from a defined url.
- __transparentBackground__: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
*`injectJavascriptFileFromAsset({@required String assetFilePath})`: Injects a JavaScript file into the WebView from the flutter assets directory.
*`injectCSSCode({@required String source})`: Injects CSS into the WebView.
**Android** supports these additional options:
*`injectCSSFileFromUrl({@required String urlFile})`: Injects an external CSS file into the WebView from a defined url.
*`injectCSSFileFromAsset({@required String assetFilePath})`: Injects a CSS file into the WebView from the flutter assets directory.
- __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
*`addJavaScriptHandler({@required String handlerName, @required JavaScriptHandlerCallback callback})`: Adds a JavaScript message handler callback that listen to post messages sent from JavaScript by the handler with name `handlerName`.
- __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
*`removeJavaScriptHandler({@required String handlerName})`: Removes a JavaScript message handler previously added with the `addJavaScriptHandler()` associated to `handlerName` key.
- __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
*`takeScreenshot`: Takes a screenshot (in PNG format) of the WebView's visible viewport and returns a `Uint8List`. Returns `null` if it wasn't be able to take it.
- __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
*`setOptions({@required InAppWebViewWidgetOptions options})`: Sets the WebView options with the new options and evaluates them.
- __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
*`getOptions`: Gets the current WebView options. Returns the options with `null` value if they are not set yet.
- __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
*`getCopyBackForwardList`: Gets the `WebHistory` for this WebView. This contains the back/forward list for use in querying each item in the history stack.
- __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
*`startSafeBrowsing`: Starts Safe Browsing initialization (available only on Android).
- __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
*`setSafeBrowsingWhitelist({@required List<String> hosts})`: Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks. The list is global for all the WebViews (available only on Android).
- __textZoom__: Set text scaling of the WebView. The default value is `100`.
*`getSafeBrowsingPrivacyPolicyUrl`: Returns a URL pointing to the privacy policy for Safe Browsing reporting. This value will never be `null`.
- __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
*`clearCache`: Clears all the webview's cache.
*`clearSslPreferences`: Clears the SSL preferences table stored in response to proceeding with SSL certificate errors (available only on Android).
**iOS** supports these additional options:
*`clearClientCertPreferences`: Clears the client certificate preferences stored in response to proceeding/cancelling client cert requests (available only on Android).
*`findAllAsync({@required String find})`: Finds all instances of find on the page and highlights them. Notifies `onFindResultReceived` listener.
- __disallowOverScroll__: Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.
*`findNext({@required bool forward})`: Highlights and scrolls to the next match found by `findAllAsync()`. Notifies `onFindResultReceived` listener.
- __enableViewportScale__: Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`.
*`clearMatches`: Clears the highlighting surrounding text matches created by `findAllAsync()`.
- __suppressesIncrementalRendering__: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory.. The default value is `false`.
*`getTRexRunnerHtml`: Gets the html (with javascript) of the Chromium's t-rex runner game. Used in combination with `getTRexRunnerCss()`.
- __allowsAirPlayForMediaPlayback__: Set to `true` to allow AirPlay. The default value is `true`.
*`getTRexRunnerCss`: Gets the css of the Chromium's t-rex runner game. Used in combination with `getTRexRunnerHtml()`.
- __allowsBackForwardNavigationGestures__: Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`.
*`scrollTo({@required int x, @required int y})`: Scrolls the WebView to the position.
- __allowsLinkPreview__: Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`.
*`scrollBy({@required int x, @required int y})`: Moves the scrolled position of the WebView.
- __ignoresViewportScaleLimits__: Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent. The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`.
- __allowsInlineMediaPlayback__: Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the `webkit-playsinline` attribute to any `<video>` elements. The default value is `false`.
##### About the JavaScript handler
- __allowsPictureInPictureMediaPlayback__: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
#### Events
Event `onWebViewCreated` fires when the `InAppWebView` is created.
This is not always the same as the URL passed to `InAppWebView.onLoadStarted` because although the load for that URL has begun, the current page may not have changed.
Loads the given `assetFilePath` with optional `headers` specified as a map from name to value.
To be able to load your local files (html, 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:
```yaml
...
# 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
Returns a boolean value indicating whether the `InAppWebView` can go back or forward the given number of steps. Steps is negative if backward and positive if forward.
Adds a JavaScript message handler `callback` (`JavaScriptHandlerCallback`) that listen to post messages sent from JavaScript by the handler with name `handlerName`.
The Android implementation uses [addJavascriptInterface](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)).
The Android implementation uses [addJavascriptInterface](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)).
The iOS implementation uses [addScriptMessageHandler](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537172-addscriptmessagehandler?language=objc)
The iOS implementation uses [addScriptMessageHandler](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537172-addscriptmessagehandler?language=objc)
The JavaScript function that can be used to call the handler is `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args);`, where `args` are [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
The JavaScript function that can be used to call the handler is `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)`, where `args` are [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
In order to call `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)` properly, you need to wait and listen the JavaScript event `flutterInAppBrowserPlatformReady`.
In order to call `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)` properly, you need to wait and listen the JavaScript event `flutterInAppBrowserPlatformReady`.
This event will be dispatch as soon as the platform (Android or iOS) is ready to handle the `callHandler` method.
This event will be dispatched as soon as the platform (Android or iOS) is ready to handle the `callHandler` method.
`window.flutter_inappbrowser.callHandler` returns a JavaScript [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
`window.flutter_inappbrowser.callHandler` returns a JavaScript [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
that can be used to get the json result returned by `JavaScriptHandlerCallback`.
that can be used to get the json result returned by [JavaScriptHandlerCallback].
In this case, simply return data that you want to send and it will be automatically json encoded using `jsonEncode` from the `dart:convert` library.
In this case, simply return data that you want to send and it will be automatically json encoded using [jsonEncode] from the `dart:convert` library.
So, on the JavaScript side, to get data coming from the Dart side, you will use:
So, on the JavaScript side, to get data coming from the Dart side, you will use:
*`javaScriptCanOpenWindowsAutomatically`: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
*`mediaPlaybackRequiresUserGesture`: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
Takes a screenshot (in PNG format) of the WebView's visible viewport and returns a `Uint8List`. Returns `null` if it wasn't be able to take it.
*`minimumFontSize`: Sets the minimum font size. The default value is `8` for Android, `0` for iOS.
*`verticalScrollBarEnabled`: Define whether the vertical scrollbar should be drawn or not. The default value is `true`.
**NOTE for iOS**: available from iOS 11.0+.
*`horizontalScrollBarEnabled`: Define whether the horizontal scrollbar should be drawn or not. The default value is `true`.
```dart
*`resourceCustomSchemes`: List of custom schemes that the WebView must handle. Use the `onLoadResourceCustomScheme` event to intercept resource requests with custom scheme.
inAppWebViewController.takeScreenshot();
*`contentBlockers`: List of `ContentBlocker` that are a set of rules used to block content in the browser window.
```
*`preferredContentMode`: Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is `InAppWebViewUserPreferredContentMode.RECOMMENDED`.
*`useShouldInterceptAjaxRequest`: Set to `true` to be able to listen at the `shouldInterceptAjaxRequest` event. The default value is `false`.
*`useShouldInterceptFetchRequest`: Set to `true` to be able to listen at the `shouldInterceptFetchRequest` event. The default value is `false`.
*`incognito`: Set to `true` to open a browser window with incognito mode. The default value is `false`.
Sets the `InAppWebView` options with the new `options` and evaluates them.
*`cacheEnabled`: Sets whether WebView should use browser caching. The default value is `true`.
```dart
*`transparentBackground`: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
Gets the current `InAppWebView` options. Returns `null` if the options are not setted yet.
*`textZoom`: Sets the text zoom of the page in percent. The default value is `100`.
```dart
*`clearSessionCache`: Set to `true` to have the session cookie cache cleared before the new window is opened.
inAppWebViewController.getOptions();
*`builtInZoomControls`: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
```
*`displayZoomControls`: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
*`supportZoom`: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
*`databaseEnabled`: Set to `true` if you want the database storage API is enabled. The default value is `false`.
*`domStorageEnabled`: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
Gets the WebHistory for this WebView. This contains the back/forward list for use in querying each item in the history stack.
*`useWideViewPort`: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport.
This contains only a snapshot of the current state.
*`safeBrowsingEnabled`: Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links.
Multiple calls to this method may return different objects.
*`mixedContentMode`: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin.
The object returned from this method will not be updated to reflect any new state.
*`allowContentAccess`: Enables or disables content URL access within WebView. Content URL access allows WebView to load content from a content provider installed in the system. The default value is `true`.
```dart
*`allowFileAccess`: Enables or disables file access within WebView. Note that this enables or disables file system access only.
inAppWebViewController.getCopyBackForwardList();
*`allowFileAccessFromFileURLs`: Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs.
```
*`allowUniversalAccessFromFileURLs`: Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin.
*`appCachePath`: Sets the path to the Application Caches files. In order for the Application Caches API to be enabled, this option must be set a path to which the application can write.
*`blockNetworkImage`: Sets whether the WebView should not load image resources from the network (resources accessed via http and https URI schemes). The default value is `false`.
*`blockNetworkLoads`: Sets whether the WebView should not load resources from the network. The default value is `false`.
*`cacheMode`: Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed.
*`cursiveFontFamily`: Sets the cursive font family name. The default value is `"cursive"`.
*`defaultFixedFontSize`: Sets the default fixed font size. The default value is `16`.
*`defaultFontSize`: Sets the default font size. The default value is `16`.
*`defaultTextEncodingName`: Sets the default text encoding name to use when decoding html pages. The default value is `"UTF-8"`.
*`disabledActionModeMenuItems`: Disables the action mode menu items according to menuItems flag.
*`fantasyFontFamily`: Sets the fantasy font family name. The default value is `"fantasy"`.
*`fixedFontFamily`: Sets the fixed font family name. The default value is `"monospace"`.
*`forceDark`: Set the force dark mode for this WebView. The default value is `AndroidInAppWebViewForceDark.FORCE_DARK_OFF`.
*`geolocationEnabled`: Sets whether Geolocation API is enabled. The default value is `true`.
*`layoutAlgorithm`: Sets the underlying layout algorithm. This will cause a re-layout of the WebView.
*`loadWithOverviewMode`: Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width.
*`loadsImagesAutomatically`: Sets whether the WebView should load image resources. Note that this method controls loading of all images, including those embedded using the data URI scheme.
*`minimumLogicalFontSize`: Sets the minimum logical font size. The default is `8`.
*`initialScale`: Sets the initial scale for this WebView. 0 means default. The behavior for the default scale depends on the state of `useWideViewPort` and `loadWithOverviewMode`.
*`needInitialFocus`: Tells the WebView whether it needs to set a node. The default value is `true`.
*`offscreenPreRaster`: Sets whether this WebView should raster tiles when it is offscreen but attached to a window.
*`sansSerifFontFamily`: Sets the sans-serif font family name. The default value is `"sans-serif"`.
*`serifFontFamily`: Sets the serif font family name. The default value is `"sans-serif"`.
*`standardFontFamily`: Sets the standard font family name. The default value is `"sans-serif"`.
*`saveFormData`: Sets whether the WebView should save form data. In Android O, the platform has implemented a fully functional Autofill feature to store form data.
*`thirdPartyCookiesEnabled`: Boolean value to enable third party cookies in the WebView.
*`hardwareAcceleration`: Boolean value to enable Hardware Acceleration in the WebView.
##### `InAppWebView` iOS-specific options
*`disallowOverScroll`: Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.
*`enableViewportScale`: Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`.
*`suppressesIncrementalRendering`: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory. The default value is `false`.
*`allowsAirPlayForMediaPlayback`: Set to `true` to allow AirPlay. The default value is `true`.
*`allowsBackForwardNavigationGestures`: Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`.
*`allowsLinkPreview`: Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`.
*`ignoresViewportScaleLimits`: Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent.
*`allowsInlineMediaPlayback`: Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls.
*`allowsPictureInPictureMediaPlayback`: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
*`isFraudulentWebsiteWarningEnabled`: A Boolean value indicating whether warnings should be shown for suspected fraudulent content such as phishing or malware.
*`selectionGranularity`: The level of granularity with which the user can interactively select content in the web view.
*`dataDetectorTypes`: Specifying a dataDetectoryTypes value adds interactivity to web content that matches the value.
*`sharedCookiesEnabled`: Set `true` if shared cookies from `HTTPCookieStorage.shared` should used for every load request in the WebView.
#### `InAppWebView` Events
*`onWebViewCreated`: Event fired when the InAppWebView is created.
*`onLoadStart`: Event fired when the InAppWebView starts to load an url.
*`onLoadStop`: Event fired when the InAppWebView finishes loading an url.
*`onLoadError`: Event fired when the InAppWebView encounters an error loading an url.
*`onLoadHttpError`: vent fires when the InAppWebView main page receives an HTTP error.
*`onProgressChanged`: Event fired when the current progress of loading a page is changed.
*`onConsoleMessage`: Event fired when the InAppWebView receives a ConsoleMessage.
*`shouldOverrideUrlLoading`: Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
*`onLoadResource`: Event fired when the InAppWebView loads a resource.
*`onScrollChanged`: Event fired when the InAppWebView scrolls.
*`onDownloadStart`: Event fired when InAppWebView recognizes and starts a downloadable file.
*`onLoadResourceCustomScheme`: Event fired when the InAppWebView finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a CustomSchemeResponse to load a specific resource encoded to `base64`.
*`onTargetBlank`: Event fired when the InAppWebView tries to open a link with `target="_blank"`.
*`onGeolocationPermissionsShowPrompt`: Event that notifies the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin (available only on Android).
*`onJsAlert`: Event fired when javascript calls the `alert()` method to display an alert dialog.
*`onJsConfirm`: Event fired when javascript calls the `confirm()` method to display a confirm dialog.
*`onJsPrompt`: Event fired when javascript calls the `prompt()` method to display a prompt dialog.
*`onSafeBrowsingHit`: Event fired when the webview notifies that a loading URL has been flagged by Safe Browsing (available only on Android).
*`onReceivedHttpAuthRequest`: Event fired when the WebView received an HTTP authentication request. The default behavior is to cancel the request.
*`onReceivedServerTrustAuthRequest`: Event fired when the WebView need to perform server trust authentication (certificate validation).
*`onReceivedClientCertRequest`: Notify the host application to handle a SSL client certificate request.
*`onFindResultReceived`: Event fired as find-on-page operations progress.
*`shouldInterceptAjaxRequest`: Event fired when an `XMLHttpRequest` is sent to a server.
*`onAjaxReadyStateChange`: Event fired whenever the `readyState` attribute of an `XMLHttpRequest` changes.
*`onAjaxProgress`: Event fired as an `XMLHttpRequest` progress.
*`shouldInterceptFetchRequest`: Event fired when a request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API).
*`onNavigationStateChange`: Event fired when the navigation state of the InAppWebView changes.
### `InAppBrowser` class
### `InAppBrowser` class
In-App Browser using native WebView.
In-App Browser using native WebView.
`inAppBrowser.webViewController` can be used to access the `InAppWebView` API.
`inAppBrowser.webViewController` can be used to access the `InAppWebView` API.
awaitthis.webViewController.injectScriptCode("console.log({'testObject': 5});");// the message will be: [object Object]
awaitthis.webViewController.injectScriptCode("console.log('testObjectStringify', JSON.stringify({'testObject': 5}));");// the message will be: testObjectStringify {"testObject": 5}
awaitthis.webViewController.injectScriptCode("console.error('testError', false);");// the message will be: testError false
-`url`: The `url` to load. Call `encodeUriComponent()` on this if the `url` contains Unicode characters. The default value is `about:blank`.
-`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`.
All platforms support:
- __useShouldOverrideUrlLoading__: Set to `true` to be able to listen at the `shouldOverrideUrlLoading()` event. The default value is `false`.
- __useOnLoadResource__: Set to `true` to be able to listen at the `onLoadResource()` event. The default value is `false`.
- __clearCache__: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
- __userAgent__: Set the custom WebView's user-agent.
- __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`.
- __javaScriptCanOpenWindowsAutomatically__: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
- __hidden__: Set to `true` to create the browser and load the page, but not show it. The `onLoadStop` event fires when loading is complete. Omit or set to `false` (default) to have the browser open and load normally.
- __toolbarTop__: Set to `false` to hide the toolbar at the top of the WebView. The default value is `true`.
- __toolbarTopBackgroundColor__: Set the custom background color of the toolbar at the top.
- __hideUrlBar__: Set to `true` to hide the url bar on the toolbar at the top. The default value is `false`.
- __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
**Android** supports these additional options:
- __hideTitleBar__: Set to `true` if you want the title should be displayed. The default value is `false`.
- __closeOnCannotGoBack__: Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
- __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
- __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
- __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
- __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
- __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
- __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
- __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
- __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
- __progressBar__: Set to `false` to hide the progress bar at the bottom of the toolbar at the top. The default value is `true`.
- __textZoom__: Set text scaling of the WebView. The default value is `100`.
- __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
**iOS** supports these additional options:
- __disallowOverScroll__: Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.
- __toolbarBottom__: Set to `false` to hide the toolbar at the bottom of the WebView. The default value is `true`.
- __toolbarBottomBackgroundColor__: Set the custom background color of the toolbar at the bottom.
- __toolbarBottomTranslucent__: Set to `true` to set the toolbar at the bottom translucent. The default value is `true`.
- __closeButtonCaption__: Set the custom text for the close button.
- __closeButtonColor__: Set the custom color for the close button.
- __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
- __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
- __enableViewportScale__: Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`.
- __suppressesIncrementalRendering__: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory.. The default value is `false`.
- __allowsAirPlayForMediaPlayback__: Set to `true` to allow AirPlay. The default value is `true`.
- __allowsBackForwardNavigationGestures__: Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`.
- __allowsLinkPreview__: Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`.
- __ignoresViewportScaleLimits__: Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent. The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`.
- __allowsInlineMediaPlayback__: Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the `webkit-playsinline` attribute to any `<video>` elements. The default value is `false`.
- __allowsPictureInPictureMediaPlayback__: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
- __spinner__: Set to `false` to hide the spinner when the WebView is loading a page. The default value is `true`.
Opens the given `assetFilePath` file in a new `InAppBrowser` instance. The other arguments are the same of `InAppBrowser.open()`.
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:
```yaml
...
# 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
This is a static method that opens an `url` in the system browser. You wont be able to use the `InAppBrowser` methods here!
*`open({String url = "about:blank", Map<String, String> headers = const {}, InAppBrowserClassOptions options})`: Opens an `url` in a new `InAppBrowser` instance.
*`openFile({@required String assetFilePath, Map<String, String> headers = const {}, InAppBrowserClassOptions options})`: Opens the given `assetFilePath` file in a new `InAppBrowser` instance. The other arguments are the same of `InAppBrowser.open`.
*`openData({@required String data, String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank", InAppBrowserClassOptions options})`: Opens a new `InAppBrowser` instance with `data` as a content, using `baseUrl` as the base URL for it.
*`openWithSystemBrowser({@required String url})`: This is a static method that opens an `url` in the system browser. You wont be able to use the `InAppBrowser` methods here!
*`show`: Displays an `InAppBrowser` window that was opened hidden. Calling this has no effect if the `InAppBrowser` was already visible.
*`hide`: Hides the `InAppBrowser` window. Calling this has no effect if the `InAppBrowser` was already hidden.
*`close`: Closes the `InAppBrowser` window.
*`isHidden`: Check if the Web View of the `InAppBrowser` instance is hidden.
*`setOptions({@required InAppBrowserClassOptions options})`: Sets the `InAppBrowser` options with the new `options` and evaluates them.
*`getOptions`: Gets the current `InAppBrowser` options as a `Map`. Returns `null` if the options are not setted yet.
*`isOpened`: Returns `true` if the `InAppBrowser` instance is opened, otherwise `false`.
```dart
#### `InAppBrowser` options
InAppBrowser.openWithSystemBrowser(Stringurl);
```
#### Future\<void\> InAppBrowser.show
They are the same of the `InAppWebView` class.
Specific options of the `InAppBrowser` class are:
Displays an `InAppBrowser` window that was opened hidden. Calling this has no effect if the `InAppBrowser` was already visible.
##### `InAppBrowser` Cross-platform options
```dart
*`hidden`: Set to `true` to create the browser and load the page, but not show it. Omit or set to `false` to have the browser open and load normally. The default value is `false`.
inAppBrowser.show();
*`toolbarTop`: Set to `false` to hide the toolbar at the top of the WebView. The default value is `true`.
```
*`toolbarTopBackgroundColor`: Set the custom background color of the toolbar at the top.
*`hideUrlBar`: Set to `true` to hide the url bar on the toolbar at the top. The default value is `false`.
#### Future\<void\> InAppBrowser.hide
##### `InAppBrowser` Android-specific options
Hides the `InAppBrowser` window. Calling this has no effect if the `InAppBrowser` was already hidden.
*`hideTitleBar`: Set to `true` if you want the title should be displayed. The default value is `false`.
*`toolbarTopFixedTitle`: Set the action bar's title.
*`closeOnCannotGoBack`: Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
*`progressBar`: Set to `false` to hide the progress bar at the bottom of the toolbar at the top. The default value is `true`.
```dart
##### `InAppBrowser` iOS-specific options
inAppBrowser.hide();
```
#### Future\<void\> InAppBrowser.close
*`toolbarBottom`: Set to `false` to hide the toolbar at the bottom of the WebView. The default value is `true`.
*`toolbarBottomBackgroundColor`: Set the custom background color of the toolbar at the bottom.
*`toolbarBottomTranslucent`: Set to `true` to set the toolbar at the bottom translucent. The default value is `true`.
*`closeButtonCaption`: Set the custom text for the close button.
*`closeButtonColor`: Set the custom color for the close button.
*`presentationStyle`: Set the custom modal presentation style when presenting the WebView. The default value is `IosWebViewOptionsPresentationStyle.FULL_SCREEN`.
*`transitionStyle`: Set to the custom transition style when presenting the WebView. The default value is `IosWebViewOptionsTransitionStyle.COVER_VERTICAL`.
*`spinner`: Set to `false` to hide the spinner when the WebView is loading a page. The default value is `true`.
Closes the `InAppBrowser` window.
#### `InAppBrowser` Events
```dart
They are the same of the `InAppWebView` class, except for `InAppWebView.onWebViewCreated` event.
inAppBrowser.close();
Specific events of the `InAppBrowser` class are:
```
#### Future\<bool\> InAppBrowser.isHidden
*`onBrowserCreated`: Event fired when the `InAppBrowser` is created.
*`onExit`: Event fired when the `InAppBrowser` window is closed.
Check if the Web View of the `InAppBrowser` instance is hidden.
```dart
inAppBrowser.isHidden();
```
#### Future\<void\> InAppBrowser.setOptions
Sets the `InAppBrowser` options and the `InAppWebView` options with the new `options` and evaluates them.
Event `onScrollChanged` fires when the `InAppBrowser` webview scrolls.
`x` represents the current horizontal scroll origin in pixels.
`y` represents the current vertical scroll origin in pixels.
```dart
@override
voidonScrollChanged(intx,inty){
}
```
### `ChromeSafariBrowser` class
### `ChromeSafariBrowser` class
[Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS.
[Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS.
You can initialize the `ChromeSafariBrowser` instance with an `InAppBrowser` fallback instance.
You can initialize the `ChromeSafariBrowser` instance with an `InAppBrowser` fallback instance.
...
@@ -1100,11 +651,9 @@ class MyInAppBrowser extends InAppBrowser {
...
@@ -1100,11 +651,9 @@ class MyInAppBrowser extends InAppBrowser {
Opens an `url` in a new `ChromeSafariBrowser` instance.
-`url`: The `url` to load. Call `encodeUriComponent()` on this if the `url` contains Unicode characters.
*`open({@required String url, ChromeSafariBrowserClassOptions options, Map<String, String> headersFallback = const {}, InAppBrowserClassOptions optionsFallback})`: Opens an `url` in a new `ChromeSafariBrowser` instance.
*`isOpened`: Returns `true` if the `ChromeSafariBrowser` instance is opened, otherwise `false`.
-`options`: Options for the `ChromeSafariBrowser`.
#### `ChromeSafariBrowser` options
-`headersFallback`: The additional header of the `InAppBrowser` instance fallback to be used in the HTTP request for this URL, specified as a map from name to value.
-`optionsFallback`: Options used by the `InAppBrowser` instance fallback.
*`addShareButton`: Set to `false` if you don't want the default share button. The default value is `true`.
*`showTitle`: Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
*`toolbarBackgroundColor`: Set the custom background color of the toolbar.
*`enableUrlBarHiding`: Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
*`instantAppsEnabled`: Set to `true` to enable Instant Apps. The default value is `false`.
**Android** supports these options:
##### `ChromeSafariBrowser` iOS-specific options
- __addShareButton__: Set to `false` if you don't want the default share button. The default value is `true`.
*`entersReaderIfAvailable`: Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
- __showTitle__: Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
*`barCollapsingEnabled`: Set to `true` to enable bar collapsing. The default value is `false`.
- __toolbarBackgroundColor__: Set the custom background color of the toolbar.
*`dismissButtonStyle`: Set the custom style for the dismiss button. The default value is `IosSafariOptionsDismissButtonStyle.DONE`.
- __enableUrlBarHiding__: Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
*`preferredBarTintColor`: Set the custom background color of the navigation bar and the toolbar.
- __instantAppsEnabled__: Set to `true` to enable Instant Apps. The default value is `false`.
*`preferredControlTintColor`: Set the custom color of the control buttons on the navigation bar and the toolbar.
*`presentationStyle`: Set the custom modal presentation style when presenting the WebView. The default value is `IosWebViewOptionsPresentationStyle.FULL_SCREEN`.
*`transitionStyle`: Set to the custom transition style when presenting the WebView. The default value is `IosWebViewOptionsTransitionStyle.COVER_VERTICAL`.
**iOS** supports these options:
#### `ChromeSafariBrowser` Events
- __entersReaderIfAvailable__: Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
*`onOpened`: Event fires when the `ChromeSafariBrowser` is opened.
- __barCollapsingEnabled__: Set to `true` to enable bar collapsing. The default value is `false`.
*`onLoaded`: Event fires when the `ChromeSafariBrowser` is loaded.
- __dismissButtonStyle__: Set the custom style for the dismiss button. The default value is `0 //done`. See [SFSafariViewController.DismissButtonStyle](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle) for all the available styles.
*`onClosed`: Event fires when the `ChromeSafariBrowser` is closed.
- __preferredBarTintColor__: Set the custom background color of the navigation bar and the toolbar.
- __preferredControlTintColor__: Set the custom color of the control buttons on the navigation bar and the toolbar.
- __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
- __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
Event `onOpened` fires when the `ChromeSafariBrowser` is opened.
```dart
@override
voidonOpened(){
}
```
Event `onLoaded` fires when the `ChromeSafariBrowser` is loaded.
```dart
@override
voidonLoaded(){
}
```
Event `onClosed` fires when the `ChromeSafariBrowser` is closed.
```dart
@override
voidonClosed(){
}
```
### `InAppLocalhostServer` class
### `InAppLocalhostServer` class
This class allows you to create a simple server on `http://localhost:[port]/` in order to be able to load your assets file on a server. The default `port` value is `8080`.
This class allows you to create a simple server on `http://localhost:[port]/` in order to be able to load your assets file on a server. The default `port` value is `8080`.
Example:
Example:
...
@@ -1261,20 +771,36 @@ Future main() async {
...
@@ -1261,20 +771,36 @@ Future main() async {
@override
@override
Widgetbuild(BuildContextcontext){
Widgetbuild(BuildContextcontext){
returnnewMaterialApp(
returnMaterialApp(
home:newScaffold(
home:Scaffold(
appBar:newAppBar(
appBar:AppBar(
title:constText('Flutter InAppBrowser Plugin example app'),
**NOTE for iOS**: For the iOS Platform, you need to add the `NSAllowsLocalNetworking` key with `true` in the `Info.plist` file (See [ATS Configuration Basics](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35)):
```xml
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
```
The `NSAllowsLocalNetworking` key is available since **iOS 10**.
```dart
localhostServer.start();
```
#### Future\<void\> InAppLocalhostServer.close
Closes the server.
```dart
*`start`: Starts a server on `http://localhost:[port]/`.
*`instance`: Gets the cookie manager shared instance.
*`setCookie({@required String url, @required String name, @required String value, String domain, String path = "/", int expiresDate, int maxAge, bool isSecure })`: Sets a cookie for the given `url`. Any existing cookie with the same `host`, `path` and `name` will be replaced with the new cookie. The cookie being set will be ignored if it is expired.
*`getCookies({@required String url})`: Gets all the cookies for the given `url`.
*`getCookie({@required String url, @required String name})`: Gets a cookie by its `name` for the given `url`.
*`deleteCookie({@required String url, @required String name, String domain = "", String path = "/"})`: Removes a cookie by its `name` for the given `url`, `domain` and `path`.
*`deleteCookies({@required String url, String domain = "", String path = "/"})`: Removes all cookies for the given `url`, `domain` and `path`.
*`deleteAllCookies()`: Removes all cookies.
Removes all cookies for the given `url`, `domain` and `path`.
### `HttpAuthCredentialDatabase` class
The default value of `path` is `"/"`.
This class implements a singleton object (shared instance) which manages the shared HTTP auth credentials cache.
If `domain` is `null` or empty, its default value will be the domain name of `url`.
On iOS, this class uses the [URLCredentialStorage](https://developer.apple.com/documentation/foundation/urlcredentialstorage) class.
```dart
On Android, this class has a custom implementation using `android.database.sqlite.SQLiteDatabase` because [WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase) doesn't offer the same functionalities as iOS `URLCredentialStorage`.
*`getAllAuthCredentials`: Gets a map list of all HTTP auth credentials saved.
CookieManager.deleteAllCookies();
*`getHttpAuthCredentials({@required ProtectionSpace protectionSpace})`: Gets all the HTTP auth credentials saved for that `protectionSpace`.
```
*`setHttpAuthCredential({@required ProtectionSpace protectionSpace, @required HttpAuthCredential credential})`: Saves an HTTP auth `credential` for that `protectionSpace`.
*`removeHttpAuthCredential({@required ProtectionSpace protectionSpace, @required HttpAuthCredential credential})`: Removes an HTTP auth `credential` for that `protectionSpace`.
*`removeHttpAuthCredentials({@required ProtectionSpace protectionSpace})`: Removes all the HTTP auth credentials saved for that `protectionSpace`.
*`clearAllAuthCredentials()`: Removes all the HTTP auth credentials saved in the database.
///Event fires when the [InAppBrowser] webview loads a resource.
///Event fired when the [InAppBrowser] webview loads a resource.
///
///
///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewOptions.useOnLoadResource] and [InAppWebViewOptions.javaScriptEnabled] options to `true`.
///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewOptions.useOnLoadResource] and [InAppWebViewOptions.javaScriptEnabled] options to `true`.
voidonLoadResource(LoadedResourceresource){
voidonLoadResource(LoadedResourceresource){
}
}
///Event fires when the [InAppBrowser] webview scrolls.
///Event fired when the [InAppBrowser] webview scrolls.
///
///
///[x] represents the current horizontal scroll origin in pixels.
///[x] represents the current horizontal scroll origin in pixels.
///
///
...
@@ -352,7 +352,7 @@ class InAppBrowser {
...
@@ -352,7 +352,7 @@ class InAppBrowser {
}
}
///Event fires when [InAppBrowser] recognizes and starts a downloadable file.
///Event fired when [InAppBrowser] recognizes and starts a downloadable file.
///
///
///[url] represents the url of the file.
///[url] represents the url of the file.
///
///
...
@@ -361,7 +361,7 @@ class InAppBrowser {
...
@@ -361,7 +361,7 @@ class InAppBrowser {
}
}
///Event fires when the [InAppBrowser] webview finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
///Event fired when the [InAppBrowser] webview finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
///
///
///[scheme] represents the scheme of the url.
///[scheme] represents the scheme of the url.
///
///
...
@@ -371,7 +371,7 @@ class InAppBrowser {
...
@@ -371,7 +371,7 @@ class InAppBrowser {
}
}
///Event fires when the [InAppBrowser] webview tries to open a link with `target="_blank"`.
///Event fired when the [InAppBrowser] webview tries to open a link with `target="_blank"`.
///
///
///[url] represents the url of the link.
///[url] represents the url of the link.
///
///
...
@@ -386,13 +386,13 @@ class InAppBrowser {
...
@@ -386,13 +386,13 @@ class InAppBrowser {
///
///
///[origin] represents the origin of the web content attempting to use the Geolocation API.
///[origin] represents the origin of the web content attempting to use the Geolocation API.
///Event fires when the WebView received an HTTP authentication request. The default behavior is to cancel the request.
///Event fired when the WebView received an HTTP authentication request. The default behavior is to cancel the request.
///
///
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [HttpAuthChallenge].
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [HttpAuthChallenge].
// ignore: missing_return
// ignore: missing_return
...
@@ -441,7 +441,7 @@ class InAppBrowser {
...
@@ -441,7 +441,7 @@ class InAppBrowser {
}
}
///Event fires when the WebView need to perform server trust authentication (certificate validation).
///Event fired when the WebView need to perform server trust authentication (certificate validation).
///The host application must return either [ServerTrustAuthResponse] instance with [ServerTrustAuthResponseAction.CANCEL] or [ServerTrustAuthResponseAction.PROCEED].
///The host application must return either [ServerTrustAuthResponse] instance with [ServerTrustAuthResponseAction.CANCEL] or [ServerTrustAuthResponseAction.PROCEED].
///
///
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [ServerTrustChallenge].
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [ServerTrustChallenge].
...
@@ -506,7 +506,7 @@ class InAppBrowser {
...
@@ -506,7 +506,7 @@ class InAppBrowser {
}
}
///Event fired when an request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API).
///Event fired when a request is sent to a server through [Fetch API](https://developer.mozilla.org/it/docs/Web/API/Fetch_API).
///It gives the host application a chance to take control over the request before sending it.
///It gives the host application a chance to take control over the request before sending it.
///Event fires when the [InAppWebView] loads a resource.
///Event fired when the [InAppWebView] loads a resource.
///
///
///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewOptions.useOnLoadResource] and [InAppWebViewOptions.javaScriptEnabled] options to `true`.
///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewOptions.useOnLoadResource] and [InAppWebViewOptions.javaScriptEnabled] options to `true`.
///Event fires when the [InAppWebView] finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
///Event fired when the [InAppWebView] finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
///Event fires when the WebView need to perform server trust authentication (certificate validation).
///Event fired when the WebView need to perform server trust authentication (certificate validation).
///The host application must return either [ServerTrustAuthResponse] instance with [ServerTrustAuthResponseAction.CANCEL] or [ServerTrustAuthResponseAction.PROCEED].
///The host application must return either [ServerTrustAuthResponse] instance with [ServerTrustAuthResponseAction.CANCEL] or [ServerTrustAuthResponseAction.PROCEED].
///
///
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [ServerTrustChallenge].
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [ServerTrustChallenge].
...
@@ -194,7 +194,7 @@ class InAppWebView extends StatefulWidget {
...
@@ -194,7 +194,7 @@ class InAppWebView extends StatefulWidget {
///Inside the `window.addEventListener("flutterInAppBrowserPlatformReady")` event, the ajax requests will be intercept for sure.
///Inside the `window.addEventListener("flutterInAppBrowserPlatformReady")` event, the ajax requests will be intercept for sure.
///Goes forward in the history of the [InAppWebView].
///Goes forward in the history of the WebView.
Future<void>goForward()async{
Future<void>goForward()async{
Map<String,dynamic>args=<String,dynamic>{};
Map<String,dynamic>args=<String,dynamic>{};
if(_inAppBrowserUuid!=null&&_inAppBrowser!=null){
if(_inAppBrowserUuid!=null&&_inAppBrowser!=null){
...
@@ -1019,7 +1019,7 @@ class InAppWebViewController {
...
@@ -1019,7 +1019,7 @@ class InAppWebViewController {
await_channel.invokeMethod('goForward',args);
await_channel.invokeMethod('goForward',args);
}
}
///Returns a boolean value indicating whether the [InAppWebView] can move forward.
///Returns a boolean value indicating whether the WebView can move forward.
Future<bool>canGoForward()async{
Future<bool>canGoForward()async{
Map<String,dynamic>args=<String,dynamic>{};
Map<String,dynamic>args=<String,dynamic>{};
if(_inAppBrowserUuid!=null&&_inAppBrowser!=null){
if(_inAppBrowserUuid!=null&&_inAppBrowser!=null){
...
@@ -1148,7 +1148,7 @@ class InAppWebViewController {
...
@@ -1148,7 +1148,7 @@ class InAppWebViewController {
///The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
///The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
///
///
///In order to call `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)` properly, you need to wait and listen the JavaScript event `flutterInAppBrowserPlatformReady`.
///In order to call `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)` properly, you need to wait and listen the JavaScript event `flutterInAppBrowserPlatformReady`.
///This event will be dispatch as soon as the platform (Android or iOS) is ready to handle the `callHandler` method.
///This event will be dispatched as soon as the platform (Android or iOS) is ready to handle the `callHandler` method.
///Sets the text zoom of the page in percent. The default is `100`.
///Sets the text zoom of the page in percent. The default value is `100`.
inttextZoom;
inttextZoom;
///Set to `true` to have the session cookie cache cleared before the new window is opened.
///Set to `true` to have the session cookie cache cleared before the new window is opened.
boolclearSessionCache;
boolclearSessionCache;
...
@@ -278,7 +278,7 @@ class AndroidInAppWebViewOptions implements WebViewOptions, BrowserOptions, Andr
...
@@ -278,7 +278,7 @@ class AndroidInAppWebViewOptions implements WebViewOptions, BrowserOptions, Andr
boolloadsImagesAutomatically;
boolloadsImagesAutomatically;
///Sets the minimum logical font size. The default is `8`.
///Sets the minimum logical font size. The default is `8`.
intminimumLogicalFontSize;
intminimumLogicalFontSize;
///Sets the initial scale for this WebView. 0 means default.The behavior for the default scale depends on the state of [useWideViewPort] and [loadWithOverviewMode].
///Sets the initial scale for this WebView. 0 means default.The behavior for the default scale depends on the state of [useWideViewPort] and [loadWithOverviewMode].
///If the content fits into the WebView control by width, then the zoom is set to 100%. For wide content, the behavior depends on the state of [loadWithOverviewMode].
///If the content fits into the WebView control by width, then the zoom is set to 100%. For wide content, the behavior depends on the state of [loadWithOverviewMode].
///If its value is true, the content will be zoomed out to be fit by width into the WebView control, otherwise not.
///If its value is true, the content will be zoomed out to be fit by width into the WebView control, otherwise not.
///If initial scale is greater than 0, WebView starts with this value as initial scale.
///If initial scale is greater than 0, WebView starts with this value as initial scale.