You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 840a049
Browse filesBrowse the repository at this point in the historyBrowse files
[webview_flutter] Copies app-facing implementation of webview_flutter from v4_webview (flutter#6856)
* copy code from v4_webview
* version bump and readme update
* work towards better readme
* improvements
* more readme progress
* improvements
* fix main and update more readme
* excerpt changes and more 3.0 diffs
* cookie manager update
* remove packages from exclude list
* lint
* better range
* isForMainFrame
* load page after waiting for widget
* fix integration tests
* improve readme a bit
* collapse changelong. update platform-specific wording. include in excerpt tests
* use platform implementation packages
* include missing exports
* PR comments
* correct spelling
* interface dev dependency
* move other usage above migration
* remove interface classes
On iOS the WebView widget is backed by a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview);
9
+
On iOS the WebView widget is backed by a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview).
8
10
On Android the WebView widget is backed by a [WebView](https://developer.android.com/reference/android/webkit/WebView).
9
11
10
12
|| Android | iOS |
11
13
|-------------|----------------|------|
12
14
|**Support**| SDK 19+ or 20+ | 9.0+ |
13
15
14
16
## Usage
15
-
Add `webview_flutter` as a [dependency in your pubspec.yaml file](https://flutter.dev/docs/development/platform-integration/platform-channels). If you are targeting Android, make sure to read the *Android Platform Views* section below to choose the platform view mode that best suits your needs.
16
-
17
-
You can now include a WebView widget in your widget tree. See the
widget's Dartdoc for more details on how to use the widget.
17
+
Add `webview_flutter` as a [dependency in your pubspec.yaml file](https://pub.dev/packages/webview_flutter/install).
18
+
19
+
You can now display a WebView by:
20
+
21
+
1. Instantiating a [WebViewController](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController-class.html).
[Platform Views](https://flutter.dev/docs/development/platform-integration/platform-views) to embed
24
-
the Android’s webview within the Flutter app. It supports two modes:
25
-
*hybrid composition* (the current default) and *virtual display*.
47
+
2. Passing the controller to a [WebViewWidget](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewWidget-class.html).
26
48
27
-
Here are some points to consider when choosing between the two:
See the Dartdocs for [WebViewController](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController-class.html)
61
+
and [WebViewWidget](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewWidget-class.html)
62
+
for more details.
34
63
64
+
### Android Platform Views
35
65
36
-
### Using Hybrid Composition
66
+
This plugin uses
67
+
[Platform Views](https://flutter.dev/docs/development/platform-integration/platform-views) to embed
68
+
the Android’s WebView within the Flutter app.
37
69
38
-
The mode is currently enabled by default. You should however make sure to set the correct `minSdkVersion` in `android/app/build.gradle` if it was previously lower than 19:
70
+
You should however make sure to set the correct `minSdkVersion` in `android/app/build.gradle` if it was previously lower than 19:
39
71
40
72
```groovy
41
73
android {
@@ -45,47 +77,67 @@ android {
45
77
}
46
78
```
47
79
48
-
### Using Virtual displays
80
+
### Platform-Specific Features
49
81
50
-
1. Set the correct `minSdkVersion` in `android/app/build.gradle` (if it was previously lower than 20):
82
+
Many classes have a subclass or an underlying implementation that provides access to platform-specific
83
+
features.
51
84
52
-
```groovy
53
-
android {
54
-
defaultConfig {
55
-
minSdkVersion 20
56
-
}
57
-
}
58
-
```
85
+
To access platform-specific features, start by adding the platform implementation packages to your
86
+
app or package:
59
87
60
-
2. Set `WebView.platform = AndroidWebView();` in `initState()`.
if (controller.platform is AndroidWebViewController) {
130
+
AndroidWebViewController.enableDebugging(true);
131
+
(controller.platform as AndroidWebViewController)
132
+
.setMediaPlaybackRequiresUserGesture(false);
133
+
}
134
+
```
135
+
136
+
See https://pub.dev/documentation/webview_flutter_android/latest/webview_flutter_android/webview_flutter_android-library.html
137
+
for more details on Android features.
138
+
139
+
See https://pub.dev/documentation/webview_flutter_wkwebview/latest/webview_flutter_wkwebview/webview_flutter_wkwebview-library.html
140
+
for more details on iOS features.
89
141
90
142
### Enable Material Components for Android
91
143
@@ -95,4 +147,76 @@ follow the steps described in the [Enabling Material Components instructions](ht
95
147
### Setting custom headers on POST requests
96
148
97
149
Currently, setting custom headers when making a post request with the WebViewController's `loadRequest` method is not supported on Android.
98
-
If you require this functionality, a workaround is to make the request manually, and then load the response data using `loadHTMLString` instead.
150
+
If you require this functionality, a workaround is to make the request manually, and then load the response data using `loadHtmlString` instead.
151
+
152
+
## Migrating from 3.0 to 4.0
153
+
154
+
### Instantiating WebViewController
155
+
156
+
In version 3.0 and below, `WebViewController` could only be retrieved in a callback after the
157
+
`WebView` was added to the widget tree. Now, `WebViewController` must be instantiated and can be
158
+
used before it is added to the widget tree. See `Usage` section above for an example.
159
+
160
+
### Replacing WebView Functionality
161
+
162
+
The `WebView` class has been removed and its functionality has been split into `WebViewController`
163
+
and `WebViewWidget`.
164
+
165
+
`WebViewController` handles all functionality that is associated with the underlying web view
166
+
provided by each platform. (e.g., loading a url, setting the background color of the underlying
167
+
platform view, or clearing the cache).
168
+
169
+
`WebViewWidget` takes a `WebViewController` and handles all Flutter widget related functionality
170
+
(e.g., layout direction, gesture recognizers).
171
+
172
+
See the Dartdocs for [WebViewController](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewController-class.html)
173
+
and [WebViewWidget](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewWidget-class.html)
174
+
for more details.
175
+
176
+
### PlatformView Implementation on Android
177
+
178
+
The PlatformView implementation for Android is currently no longer configurable. It uses Texture
179
+
Layer Hybrid Composition on versions 23+ and automatically fallbacks to Hybrid Composition for
180
+
version 19-23. See https://github.com/flutter/flutter/issues/108106 for progress on manually
181
+
switching to Hybrid Composition on versions 23+.
182
+
183
+
### API Changes
184
+
185
+
Below is a non-exhaustive list of changes to the API:
186
+
187
+
*`WebViewController.clearCache` no longer clears local storage. Please use
188
+
`WebViewController.clearLocalStorage`.
189
+
*`WebViewController.clearCache` no longer reloads the page.
190
+
*`WebViewController.loadUrl` has been removed. Please use `WebViewController.loadRequest`.
191
+
*`WebViewController.evaluateJavascript` has been removed. Please use
192
+
`WebViewController.runJavaScript` or `WebViewController.runJavaScriptReturningResult`.
193
+
*`WebViewController.getScrollX` and `WebViewController.getScrollY` have been removed and have
194
+
been replaced by `WebViewController.getScrollPosition`.
195
+
*`WebViewController.runJavaScriptReturningResult` now returns an `Object` and not a `String`. This
196
+
will attempt to return a `bool` or `num` if the return value can be parsed.
197
+
*`CookieManager` is replaced by `WebViewCookieManager`.
198
+
*`NavigationDelegate.onWebResourceError` callback includes errors that are not from the main frame.
199
+
Use the `WebResourceError.isForMainFrame` field to filter errors.
200
+
* The following fields from `WebView` have been moved to `NavigationDelegate`. They can be added to
201
+
a WebView with `WebViewController.setNavigationDelegate`.
0 commit comments