Skip to content

Commit c5a35fd

Browse files
authored
Merge pull request #86 from gerryhigh/master
Add 'show', 'hide', and 'reloadUrl' functions
2 parents e6b1a59 + 517342a commit c5a35fd

File tree

12 files changed

+2110
-7865
lines changed

12 files changed

+2110
-7865
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+

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/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
5757
case "forward":
5858
forward(call, result);
5959
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;
6069
default:
6170
result.notImplemented();
6271
break;
@@ -145,6 +154,20 @@ private void reload(MethodCall call, MethodChannel.Result result) {
145154
webViewManager.reload(call, result);
146155
}
147156
}
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+
}
148171
private void eval(MethodCall call, final MethodChannel.Result result) {
149172
if (webViewManager != null) {
150173
webViewManager.eval(call, result);
@@ -158,6 +181,16 @@ private void resize(MethodCall call, final MethodChannel.Result result) {
158181
}
159182
result.success(null);
160183
}
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+
}
161194

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,14 @@ boolean canGoBack() {
162162
boolean canGoForward() {
163163
return webView.canGoForward();
164164
}
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+
}
165175
}

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/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)