Skip to content

Commit 7e2cef1

Browse files
authored
Merge branch 'master' into master
2 parents 8495514 + 90f7cf4 commit 7e2cef1

File tree

12 files changed

+254
-33
lines changed

12 files changed

+254
-33
lines changed

.github/ISSUE_TEMPLATE/BUG.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
name: I have found out bug in plugin.
3+
about: You are writing an Flutter application with this webview plugin but the application is crashing
4+
or throws an exception, a plugin is buggy, or something looks wrong.
5+
title: ''
6+
labels: ''
7+
assignees: ''
8+
9+
---
10+
11+
<!-- Thank you for using Flutter Webview plugin!
12+
13+
If you are looking for support, please check out our documentation
14+
or consider asking a question on Stack Overflow:
15+
* https://flutter.dev/
16+
* https://api.flutter.dev/
17+
* https://stackoverflow.com/questions/tagged/flutter?sort=frequent
18+
19+
If you have found a bug or if our documentation doesn't have an answer
20+
to what you're looking for, then fill our the template below. Please read
21+
our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
22+
-->
23+
24+
## System info
25+
26+
Issue occurs on: iOS / Android / both
27+
Plugin version: xxx
28+
Flutter doctor output:
29+
30+
```
31+
paste it here...
32+
```
33+
34+
## Steps to Reproduce
35+
36+
<!--
37+
Please tell us exactly how to reproduce the problem you are running into.
38+
39+
Please attach a small application (ideally just one main.dart file) that
40+
reproduces the problem. You could use https://gist.github.com/ for this.
41+
42+
If the problem is with your application's rendering, then please attach
43+
a screenshot and explain what the problem is.
44+
-->
45+
46+
1. ...
47+
2. ...
48+
3. ...
49+
50+
## Logs
51+
52+
<!--
53+
Run your application with `flutter run --verbose` and attach all the
54+
log output below between the lines with the backticks. If there is an
55+
exception, please see if the error message includes enough information
56+
to explain how to solve the issue.
57+
-->
58+
59+
```
60+
```
61+
62+
<!--
63+
Run `flutter analyze` and attach any output of that command below.
64+
If there are any analysis errors, try resolving them before filing this issue.
65+
-->
66+
67+
```
68+
```
69+
70+
<!-- Finally, paste the output of running `flutter doctor -v` here. -->
71+
72+
```
73+
```

.github/ISSUE_TEMPLATE/SUPPORT.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: I want help writing my application
3+
about: You have a question for how to achieve a particular effect, or you need help
4+
with using a particular API.
5+
title: ''
6+
labels: ''
7+
assignees: ''
8+
9+
---
10+
11+
<!-- Thank you for using Flutter!
12+
13+
Please check out our documentation first:
14+
* https://flutter.dev/
15+
* https://api.flutter.dev/
16+
17+
If you can't find the answer there, please consider asking a question on
18+
the Stack Overflow Web site:
19+
* https://stackoverflow.com/questions/tagged/flutter?sort=frequent
20+
21+
Please don't file a GitHub issue for support requests. GitHub issues are
22+
for tracking defects in the product. If you file a bug asking for help, we
23+
will consider this a request for a documentation update.
24+
25+
-->
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: Feature request
3+
about: Suggest a new idea for Flutter webview plugin.
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Thank you for using Flutter!
11+
12+
If you are looking for support, please check out our documentation
13+
or consider asking a question on Stack Overflow:
14+
* https://flutter.dev/
15+
* https://api.flutter.dev/
16+
* https://stackoverflow.com/questions/tagged/flutter?sort=frequent
17+
18+
If you have found a bug or if our documentation doesn't have an answer
19+
to what you're looking for, then fill our the template below. Please read
20+
our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
21+
-->
22+
23+
## Use case
24+
25+
<!--
26+
Please tell us the problem you are running into that led to you wanting
27+
a new feature.
28+
29+
Is your feature request related to a problem? Please give a clear and
30+
concise description of what the problem is.
31+
32+
Describe alternative solutions you've considered. Is there a package
33+
on pub.dev/flutter that already solves this?
34+
-->
35+
36+
## Proposal
37+
38+
<!--
39+
Briefly but precisely describe what you would like Flutter to be able to do.
40+
41+
Consider attaching images showing what you are imagining.
42+
43+
Does this have to be provided by Flutter directly, or can it be provided
44+
by a package on pub.dev/flutter? If so, maybe consider implementing and
45+
publishing such a package rather than filing a bug.
46+
-->

README.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<img src="https://img.shields.io/badge/Flutter%20Communityflutter__webview__plugin-blue.svg?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAA5CAYAAABwDahPAAAAB3RJTUUH4gYTFygnu4qzzAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAAARnQU1BAACxjwv8YQUAAAjVSURBVHjazZp5UJTnHcddWO5rd9ndd99llUMUUVhOYTnEaNAFYbk0cXJZlTRNWyqHlRtzNE0yJURFzkUSBUSjMZkYoqTT6B/SeDSYtBoOj1i1TpNpZ/yjje2MwK/P8+zhArv7vu++u05/M88Ms7M87+f7u57j3QULXGTuAUulAYuL82QJZT1KTcM4ndL4L88FP4eC/uvw7B8e4PFgy7npH7iNqR9KRwG0XV/+wiXQ3opVsaKoZ6vlieWn6NTau8q0ph9D0nfPKDVNEEiXQ/aeL2HLyLRhnMNjitPYdhFg40d3PpIma72cBu3mG+YXGLlpO5VcNRKS/gqoMl+HkIxXAf+N4IFObYQgVQWCPw9bz4MRnhv4I/jbJ5wGLvBUCEVRz5XRmvo7j6B3zxom+HX7LsDWC47CT5P/LT5+a8hp8H6Lcp6kU2omCLjR09bgA5X84bHnCwZugDy++m9eovxtvOGDY15sDsl4zarHZ3l+USVk7+WTNo/gFUkNQCXWk/SUJ1Z8IhSrpZzBhYHRUip55x8NXt9tH35hhQGet+dvAhVfh+DrzPOrkPNQV/u7ryo7kzW8pzw9Auc68TwjfCWsa73EG17Xdw1k6lri+TnPmcEcqMPd96azljPCe1OZ0UpN4z/spYwr4OXW4Y019yr4h+l0zJ6XpYYr0zjA77vIu9uQgrUHj1gCwnWFjPDugdESOrXuFht40m1a+cGTnEertCy2FhWtbXhWnsdGJVWeUbHJedRt1u//E+9FCqXNQyqhkXQc62nzCoLPYwcvWbH9DVbdBsO3fcXD8wb44mM3D7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5TssYWokn5Lp2h4aipPfHwPSdL5qe8T+XgeDXeA98zQAAAABJRU5ErkJggg==" width="800">
2-
3-
[Flutter Community](https://github.com/fluttercommunity/community)
1+
[![Flutter Community: flutter_webview_plugin](https://fluttercommunity.dev/_github/header/flutter_webview_plugin)](https://github.com/fluttercommunity/community)
42

53
# Flutter WebView Plugin
64

@@ -10,12 +8,32 @@ Plugin that allows Flutter to communicate with a native WebView.
108

119
**_Warning:_**
1210
The webview is not integrated in the widget tree, it is a native view on top of the flutter view.
13-
you won't be able to use snackbars, dialogs ...
11+
You won't be able see snackbars, dialogs, or other flutter widgets that would overlap with the region of the screen taken up by the webview.
12+
13+
The getSafeAcceptedType() function is available only for minimum SDK of 21.
14+
eval() function only supports SDK of 19 or greater for evaluating Javascript.
1415

1516
## Getting Started
1617

1718
For help getting started with Flutter, view our online [documentation](http://flutter.io/).
1819

20+
#### iOS
21+
22+
In order for plugin to work correctly, you need to add new key to `ios/Runner/Info.plist`
23+
24+
```xml
25+
<key>NSAppTransportSecurity</key>
26+
<dict>
27+
<key>NSAllowsArbitraryLoads</key>
28+
<true/>
29+
<key>NSAllowsArbitraryLoadsInWebContent</key>
30+
<true/>
31+
</dict>
32+
```
33+
34+
`NSAllowsArbitraryLoadsInWebContent` is for iOS 10+ and `NSAllowsArbitraryLoads` for iOS 9.
35+
36+
1937
### How it works
2038

2139
#### Launch WebView Fullscreen with Flutter navigation
@@ -125,6 +143,25 @@ flutterWebviewPlugin.launch(url,
125143
);
126144
```
127145

146+
#### Injecting custom code into the webview
147+
Use `flutterWebviewPlugin.evalJavaScript(String code)`. This function must be run after the page has finished loading (i.e. listen to `onStateChanged` for events where state is `finishLoad`).
148+
149+
If you have a large amount of JavaScript to embed, use an asset file. Add the asset file to `pubspec.yaml`, then call the function like:
150+
151+
```dart
152+
Future<String> loadJS(String name) async {
153+
var givenJS = rootBundle.loadString('assets/$name.js');
154+
return givenJS.then((String js) {
155+
flutterWebViewPlugin.onStateChanged.listen((viewState) async {
156+
if (viewState.type == WebViewState.finishLoad) {
157+
flutterWebViewPlugin.evalJavascript(js);
158+
}
159+
});
160+
});
161+
}
162+
```
163+
164+
128165
### Webview Events
129166

130167
- `Stream<Null>` onDestroy

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
xmlns:tools="http://schemas.android.com/tools"
33
package="com.flutter_webview_plugin">
4+
<uses-sdk android:minSdkVersion="16" />
45
<application>
56
<provider
67
android:name="androidx.core.content.FileProvider"
78
android:authorities="${applicationId}.fileprovider"
89
android:exported="false"
9-
android:grantUriPermissions="true"
10+
android:grantUriPermissions="true"
1011
tools:replace="android:authorities">
1112
<meta-data
1213
android:name="android.support.FILE_PROVIDER_PATHS"

android/src/main/java/com/flutter_webview_plugin/BrowserClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void onReceivedError(WebView view, int errorCode, String description, Str
104104
super.onReceivedError(view, errorCode, description, failingUrl);
105105
Map<String, Object> data = new HashMap<>();
106106
data.put("url", failingUrl);
107-
data.put("code", errorCode);
107+
data.put("code", Integer.toString(errorCode));
108108
FlutterWebviewPlugin.channel.invokeMethod("onHttpError", data);
109109
}
110110

android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
104104
boolean useWideViewPort = call.argument("useWideViewPort");
105105
String invalidUrlRegex = call.argument("invalidUrlRegex");
106106
boolean geolocationEnabled = call.argument("geolocationEnabled");
107+
boolean debuggingEnabled = call.argument("debuggingEnabled");
107108

108109
if (webViewManager == null || webViewManager.closed == true) {
109110
webViewManager = new WebviewManager(activity, context);
@@ -130,7 +131,8 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
130131
allowFileURLs,
131132
useWideViewPort,
132133
invalidUrlRegex,
133-
geolocationEnabled
134+
geolocationEnabled,
135+
debuggingEnabled
134136
);
135137
result.success(null);
136138
}

android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
135135
if (webView.canGoBack()) {
136136
webView.goBack();
137137
} else {
138-
close();
138+
FlutterWebviewPlugin.channel.invokeMethod("onBack", null);
139139
}
140140
return true;
141141
}
@@ -243,6 +243,10 @@ public void onProgressChanged(WebView view, int progress) {
243243
args.put("progress", progress / 100.0);
244244
FlutterWebviewPlugin.channel.invokeMethod("onProgressChanged", args);
245245
}
246+
247+
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
248+
callback.invoke(origin, true, false);
249+
}
246250
});
247251
}
248252

@@ -348,7 +352,8 @@ void openUrl(
348352
boolean allowFileURLs,
349353
boolean useWideViewPort,
350354
String invalidUrlRegex,
351-
boolean geolocationEnabled
355+
boolean geolocationEnabled,
356+
boolean debuggingEnabled
352357
) {
353358
webView.getSettings().setJavaScriptEnabled(withJavascript);
354359
webView.getSettings().setBuiltInZoomControls(withZoom);
@@ -366,17 +371,14 @@ void openUrl(
366371
webView.getSettings().setAllowUniversalAccessFromFileURLs(allowFileURLs);
367372

368373
webView.getSettings().setUseWideViewPort(useWideViewPort);
369-
374+
375+
// Handle debugging
376+
webView.setWebContentsDebuggingEnabled(debuggingEnabled);
377+
370378
webViewClient.updateInvalidUrlRegex(invalidUrlRegex);
371379

372380
if (geolocationEnabled) {
373381
webView.getSettings().setGeolocationEnabled(true);
374-
webView.setWebChromeClient(new WebChromeClient() {
375-
@Override
376-
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
377-
callback.invoke(origin, true, false);
378-
}
379-
});
380382
}
381383

382384
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

0 commit comments

Comments
 (0)