Skip to content

Commit 2ffd9d7

Browse files
authored
Merge pull request #1 from romkor/add_http_error_stream
Add http error stream
2 parents 172c27c + 10d3377 commit 2ffd9d7

File tree

19 files changed

+2283
-7885
lines changed

19 files changed

+2283
-7885
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ packages
99
pubspec.lock
1010

1111
example/ios/Podfile.lock
12+
**/Flutter/App.framework/
13+
**/Flutter/Flutter.framework/
14+
**/Flutter/Generated.xcconfig/
15+
**/Flutter/flutter_assets/
16+

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 0.1.6
2+
3+
- fix onStateChanged
4+
- Taking safe areas into account for bottom bars
5+
- iOS
6+
+ withLocalUrl option for iOS > 9.0
7+
- Android
8+
+ add reload, goBack and foForward function
9+
110
# 0.1.5
211

312
- iOS use WKWebView instead of UIWebView

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ Future<Map<String, dynamic>> getCookies();
103103
```dart
104104
Future<Null> resize(Rect rect);
105105
```
106+
```dart
107+
Future<Null> show();
108+
```
109+
```dart
110+
Future<Null> hide();
111+
```
112+
```dart
113+
Future<Null> reloadUrl(String url);
114+
```

android/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ version '1.0-SNAPSHOT'
33

44
buildscript {
55
repositories {
6+
google()
67
jcenter()
78
}
89

910
dependencies {
10-
classpath 'com.android.tools.build:gradle:2.3.0'
11+
classpath 'com.android.tools.build:gradle:3.1.2'
1112
}
1213
}
1314

@@ -21,7 +22,7 @@ apply plugin: 'com.android.library'
2122

2223
android {
2324
compileSdkVersion 25
24-
buildToolsVersion '25.0.0'
25+
buildToolsVersion '27.0.3'
2526

2627
defaultConfig {
2728
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

android/src/main/AndroidManifest.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.flutter_webview_plugin"
3-
android:versionCode="1"
4-
android:versionName="0.0.1">
2+
package="com.flutter_webview_plugin">
3+
4+
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/>
55

6-
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21"/>
76
</manifest>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.flutter_webview_plugin;
22

33
import android.graphics.Bitmap;
4+
import android.webkit.WebResourceRequest;
5+
import android.webkit.WebResourceResponse;
46
import android.webkit.WebView;
57
import android.webkit.WebViewClient;
68

@@ -37,4 +39,13 @@ public void onPageFinished(WebView view, String url) {
3739
FlutterWebviewPlugin.channel.invokeMethod("onState", data);
3840

3941
}
42+
43+
@Override
44+
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
45+
super.onReceivedHttpError(view, request, errorResponse);
46+
Map<String, Object> data = new HashMap<>();
47+
data.put("url", request.getUrl().toString());
48+
data.put("code", Integer.toString(errorResponse.getStatusCode()));
49+
FlutterWebviewPlugin.channel.invokeMethod("onError", data);
50+
}
4051
}

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
4848
case "resize":
4949
resize(call, result);
5050
break;
51+
case "reload":
52+
reload(call, result);
53+
break;
54+
case "back":
55+
back(call, result);
56+
break;
57+
case "forward":
58+
forward(call, result);
59+
break;
60+
case "hide":
61+
hide(call, result);
62+
break;
63+
case "show":
64+
show(call, result);
65+
break;
66+
case "reloadUrl":
67+
reloadUrl(call, result);
68+
break;
5169
default:
5270
result.notImplemented();
5371
break;
@@ -111,6 +129,45 @@ private void close(MethodCall call, MethodChannel.Result result) {
111129
}
112130
}
113131

132+
/**
133+
* Navigates back on the Webview.
134+
*/
135+
private void back(MethodCall call, MethodChannel.Result result) {
136+
if (webViewManager != null) {
137+
webViewManager.back(call, result);
138+
}
139+
}
140+
/**
141+
* Navigates forward on the Webview.
142+
*/
143+
private void forward(MethodCall call, MethodChannel.Result result) {
144+
if (webViewManager != null) {
145+
webViewManager.forward(call, result);
146+
}
147+
}
148+
149+
/**
150+
* Reloads the Webview.
151+
*/
152+
private void reload(MethodCall call, MethodChannel.Result result) {
153+
if (webViewManager != null) {
154+
webViewManager.reload(call, result);
155+
}
156+
}
157+
private void reloadUrl(MethodCall call, MethodChannel.Result result) {
158+
if (webViewManager != null) {
159+
String url = call.argument("url");
160+
webViewManager.openUrl(false,
161+
false,
162+
false,
163+
false,
164+
"",
165+
url,
166+
false,
167+
false
168+
);
169+
}
170+
}
114171
private void eval(MethodCall call, final MethodChannel.Result result) {
115172
if (webViewManager != null) {
116173
webViewManager.eval(call, result);
@@ -124,6 +181,16 @@ private void resize(MethodCall call, final MethodChannel.Result result) {
124181
}
125182
result.success(null);
126183
}
184+
private void hide(MethodCall call, final MethodChannel.Result result) {
185+
if (webViewManager != null) {
186+
webViewManager.hide(call, result);
187+
}
188+
}
189+
private void show(MethodCall call, final MethodChannel.Result result) {
190+
if (webViewManager != null) {
191+
webViewManager.show(call, result);
192+
}
193+
}
127194

128195
private int dp2px(Context context, float dp) {
129196
final float scale = context.getResources().getDisplayMetrics().density;

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,54 @@ public void onReceiveValue(String value) {
122122
}
123123
});
124124
}
125+
/**
126+
* Reloads the Webview.
127+
*/
128+
void reload(MethodCall call, MethodChannel.Result result) {
129+
if (webView != null) {
130+
webView.reload();
131+
}
132+
}
133+
/**
134+
* Navigates back on the Webview.
135+
*/
136+
void back(MethodCall call, MethodChannel.Result result) {
137+
if (webView != null && webView.canGoBack()) {
138+
webView.goBack();
139+
}
140+
}
141+
/**
142+
* Navigates forward on the Webview.
143+
*/
144+
void forward(MethodCall call, MethodChannel.Result result) {
145+
if (webView != null && webView.canGoForward()) {
146+
webView.goForward();
147+
}
148+
}
125149

126150
void resize(FrameLayout.LayoutParams params) {
127151
webView.setLayoutParams(params);
128152
}
153+
/**
154+
* Checks if going back on the Webview is possible.
155+
*/
156+
boolean canGoBack() {
157+
return webView.canGoBack();
158+
}
159+
/**
160+
* Checks if going forward on the Webview is possible.
161+
*/
162+
boolean canGoForward() {
163+
return webView.canGoForward();
164+
}
165+
void hide(MethodCall call, MethodChannel.Result result) {
166+
if (webView != null) {
167+
webView.setVisibility(View.INVISIBLE);
168+
}
169+
}
170+
void show(MethodCall call, MethodChannel.Result result) {
171+
if (webView != null) {
172+
webView.setVisibility(View.VISIBLE);
173+
}
174+
}
129175
}

example/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ apply plugin: 'com.android.application'
1515
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
1616

1717
android {
18-
compileSdkVersion 25
19-
buildToolsVersion '25.0.2'
18+
compileSdkVersion 27
19+
buildToolsVersion '27.0.3'
2020

2121
lintOptions {
2222
disable 'InvalidPackage'

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android:versionCode="1"
44
android:versionName="0.0.1">
55

6-
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
6+
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23" />
77

88
<!-- The INTERNET permission is required for development. Specifically,
99
flutter needs it to communicate with the running application

example/android/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
buildscript {
22
repositories {
3+
google()
34
jcenter()
5+
maven {
6+
url 'https://maven.google.com/'
7+
}
48
}
59

610
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.2.3'
11+
classpath 'com.android.tools.build:gradle:3.1.1'
812
}
913
}
1014

1115
allprojects {
1216
repositories {
17+
google()
1318
jcenter()
19+
maven {
20+
url 'https://maven.google.com/'
21+
}
1422
}
1523
}
1624

0 commit comments

Comments
 (0)