Skip to content

Commit b043b43

Browse files
v0.5.5
1 parent 53e9ecb commit b043b43

14 files changed

+729
-197
lines changed

.idea/workspace.xml

+103-76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
## 0.5.5
2+
3+
- added `getUrl` method for the `InAppWebViewController` class
4+
- added `getTitle` method for the `InAppWebViewController` class
5+
- added `getProgress` method for the `InAppWebViewController` class
6+
- added `getFavicon` method for the `InAppWebViewController` class
7+
- added `onScrollChanged` event for the `InAppWebViewController` and `InAppBrowser` class
8+
- added `onBrowserCreated` event for the `InAppBrowser` class
9+
- added `openData` method for the `InAppBrowser` class
10+
- added `initialData` property for the `InAppWebView` widget
11+
112
## 0.5.4
213

314
- added `WebHistory` and `WebHistoryItem` class
4-
- added `getCopyBackForwardList`, `goBackOrForward`, `canGoBackOrForward` and `goTo` methods for `InAppWebView` and `InAppBrowser`
15+
- added `getCopyBackForwardList`, `goBackOrForward`, `canGoBackOrForward` and `goTo` methods for the `InAppWebViewController` class
516

617
## 0.5.3
718

@@ -10,8 +21,8 @@
1021
## 0.5.2
1122

1223
- fixed some missing `result.success()` on Android and iOS
13-
- added `postUrl()` method for `InAppWebView` and `InAppBrowser`
14-
- added `loadData()` method for `InAppWebView` and `InAppBrowser`
24+
- added `postUrl()` method for the `InAppWebViewController` class
25+
- added `loadData()` method for the `InAppWebViewController` class
1526

1627
## 0.5.1
1728

README.md

+78-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Classes:
4040
- [InAppLocalhostServer](#inapplocalhostserver-class): This class allows you to create a simple server on `http://localhost:[port]/`. The default `port` value is `8080`.
4141
- [CookieManager](#cookiemanager-class): Manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+.
4242

43+
See the online [docs](https://pub.dartlang.org/documentation/flutter_inappbrowser/latest/) to get the full documentation.
44+
4345
### `InAppWebView` class
4446
Flutter Widget for adding an **inline native WebView** integrated in the flutter widget tree.
4547

@@ -193,6 +195,9 @@ Initial url that will be loaded.
193195
#### InAppWebView.initialFile
194196
Initial asset file that will be loaded. See `InAppWebView.loadFile()` for explanation.
195197

198+
#### InAppWebView.initialData
199+
Initial `InAppWebViewInitialData` that will be loaded.
200+
196201
#### InAppWebView.initialHeaders
197202
Initial headers that will be used.
198203

@@ -302,6 +307,49 @@ InAppWebView(
302307
}
303308
```
304309

310+
Event `onScrollChanged` fires when the `InAppWebView` scrolls.
311+
`x` represents the current horizontal scroll origin in pixels.
312+
`y` represents the current vertical scroll origin in pixels.
313+
```dart
314+
InAppWebView(
315+
initialUrl: "https://flutter.io/",
316+
onScrollChanged: (InAppWebViewController controller, int x, int y) {}
317+
}
318+
```
319+
320+
#### Future\<String\> InAppWebViewController.getUrl
321+
322+
Gets the URL for the current page.
323+
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.
324+
325+
```dart
326+
inAppWebViewController.getUrl();
327+
```
328+
329+
#### Future\<String\> InAppWebViewController.getTitle
330+
331+
Gets the title for the current page.
332+
333+
```dart
334+
inAppWebViewController.getTitle();
335+
```
336+
337+
#### Future\<int\> InAppWebViewController.getProgress
338+
339+
Gets the progress for the current page. The progress value is between 0 and 100.
340+
341+
```dart
342+
inAppWebViewController.getProgress();
343+
```
344+
345+
#### Future\<List\<int\>\> InAppWebViewController.getFavicon
346+
347+
Gets the favicon for the current page.
348+
349+
```dart
350+
inAppWebViewController.getFavicon();
351+
```
352+
305353
#### Future\<void\> InAppWebViewController.loadUrl
306354

307355
Loads the given `url` with optional `headers` specified as a map from name to value.
@@ -744,7 +792,7 @@ inAppBrowser.open({String url = "about:blank", Map<String, String> headers = con
744792

745793
#### Future\<void\> InAppBrowser.openFile
746794

747-
Opens the giver `assetFilePath` file in a new `InAppBrowser` instance. The other arguments are the same of `InAppBrowser.open()`.
795+
Opens the given `assetFilePath` file in a new `InAppBrowser` instance. The other arguments are the same of `InAppBrowser.open()`.
748796

749797
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!
750798

@@ -778,6 +826,16 @@ inAppBrowser.openFile("assets/index.html");
778826
inAppBrowser.openFile(String assetFilePath, {Map<String, String> headers = const {}, Map<String, dynamic> options = const {}});
779827
```
780828

829+
#### static Future\<void\> InAppBrowser.openData
830+
831+
Opens a new `InAppBrowser` instance with `data` as a content, using `baseUrl` as the base URL for it.
832+
The `mimeType` parameter specifies the format of the data.
833+
The `encoding` parameter specifies the encoding of the data.
834+
835+
```dart
836+
InAppBrowser.openData(String data, {String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank", Map<String, dynamic> options = const {}});
837+
```
838+
781839
#### static Future\<void\> InAppBrowser.openWithSystemBrowser
782840

783841
This is a static method that opens an `url` in the system browser. You wont be able to use the `InAppBrowser` methods here!
@@ -841,6 +899,14 @@ inAppBrowser.isOpened();
841899

842900
#### Events
843901

902+
Event `onBrowserCreated` fires when the `InAppBrowser` is created.
903+
```dart
904+
@override
905+
void onBrowserCreated() {
906+
907+
}
908+
```
909+
844910
Event `onLoadStart` fires when the `InAppBrowser` starts to load an `url`.
845911
```dart
846912
@override
@@ -911,6 +977,17 @@ Event `onLoadResource` fires when the `InAppBrowser` webview loads a resource.
911977
}
912978
```
913979

980+
Event `onScrollChanged` fires when the `InAppBrowser` webview scrolls.
981+
`x` represents the current horizontal scroll origin in pixels.
982+
`y` represents the current vertical scroll origin in pixels.
983+
```dart
984+
@override
985+
void onScrollChanged(int x, int y) {
986+
987+
}
988+
989+
```
990+
914991
### `ChromeSafariBrowser` class
915992
[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.
916993

android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java

+25-7
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@ public FlutterWebView(Registrar registrar, int id, HashMap<String, Object> param
4040

4141
String initialUrl = (String) params.get("initialUrl");
4242
String initialFile = (String) params.get("initialFile");
43+
Map<String, String> initialData = (Map<String, String>) params.get("initialData");
4344
Map<String, String> initialHeaders = (Map<String, String>) params.get("initialHeaders");
4445
HashMap<String, Object> initialOptions = (HashMap<String, Object>) params.get("initialOptions");
4546

4647
InAppWebViewOptions options = new InAppWebViewOptions();
4748
options.parse(initialOptions);
4849

50+
webView = new InAppWebView(context, this, id, options);
51+
webView.prepare();
52+
53+
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappwebview_" + id);
54+
channel.setMethodCallHandler(this);
55+
4956
if (initialFile != null) {
5057
try {
5158
initialUrl = Util.getUrlAsset(registrar, initialFile);
@@ -56,13 +63,15 @@ public FlutterWebView(Registrar registrar, int id, HashMap<String, Object> param
5663
}
5764
}
5865

59-
webView = new InAppWebView(context, this, id, options);
60-
webView.prepare();
61-
62-
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappwebview_" + id);
63-
channel.setMethodCallHandler(this);
64-
65-
webView.loadUrl(initialUrl, initialHeaders);
66+
if (initialData != null) {
67+
String data = initialData.get("data");
68+
String mimeType = initialData.get("mimeType");
69+
String encoding = initialData.get("encoding");
70+
String baseUrl = initialData.get("baseUrl");
71+
webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null);
72+
}
73+
else
74+
webView.loadUrl(initialUrl, initialHeaders);
6675
}
6776

6877
@Override
@@ -76,6 +85,15 @@ public void onMethodCall(MethodCall call, Result result) {
7685
String jsWrapper;
7786
String urlFile;
7887
switch (call.method) {
88+
case "getUrl":
89+
result.success((webView != null) ? webView.getUrl() : null);
90+
break;
91+
case "getTitle":
92+
result.success((webView != null) ? webView.getTitle() : null);
93+
break;
94+
case "getProgress":
95+
result.success((webView != null) ? webView.getProgress() : null);
96+
break;
7997
case "loadUrl":
8098
if (webView != null)
8199
webView.loadUrl(call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);

android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java

+36-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
5252

5353
Bundle b = getIntent().getExtras();
5454
uuid = b.getString("uuid");
55-
String url = b.getString("url");
55+
5656
HashMap<String, Object> optionsMap = (HashMap<String, Object>) b.getSerializable("options");
5757

5858
options = new InAppBrowserOptions();
@@ -62,16 +62,29 @@ protected void onCreate(Bundle savedInstanceState) {
6262
webViewOptions.parse(optionsMap);
6363
webView.options = webViewOptions;
6464

65-
headers = (HashMap<String, String>) b.getSerializable("headers");
66-
6765
InAppBrowserFlutterPlugin.webViewActivities.put(uuid, this);
6866

6967
actionBar = getSupportActionBar();
7068

7169
prepareView();
7270

73-
webView.loadUrl(url, headers);
74-
//webView.loadData("<!DOCTYPE assets> <assets lang=\"en\"> <head> <meta charset=\"UTF-8\"> <title>Document</title> </head> <body> ciao <img src=\"https://via.placeholder.com/350x150\" /> <img src=\"./images/test\" alt=\"not found\" /></body> </assets>", "text/assets", "utf8");
71+
Boolean isData = b.getBoolean("isData");
72+
if (!isData) {
73+
headers = (HashMap<String, String>) b.getSerializable("headers");
74+
String url = b.getString("url");
75+
webView.loadUrl(url, headers);
76+
}
77+
else {
78+
String data = b.getString("data");
79+
String mimeType = b.getString("mimeType");
80+
String encoding = b.getString("encoding");
81+
String baseUrl = b.getString("baseUrl");
82+
webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null);
83+
}
84+
85+
Map<String, Object> obj = new HashMap<>();
86+
obj.put("uuid", uuid);
87+
InAppBrowserFlutterPlugin.channel.invokeMethod("onBrowserCreated", obj);
7588

7689
}
7790

@@ -164,6 +177,24 @@ public void onFocusChange(View view, boolean b) {
164177
return true;
165178
}
166179

180+
public String getUrl() {
181+
if (webView != null)
182+
return webView.getUrl();
183+
return null;
184+
}
185+
186+
public String getWebViewTitle() {
187+
if (webView != null)
188+
return webView.getTitle();
189+
return null;
190+
}
191+
192+
public Integer getProgress() {
193+
if (webView != null)
194+
return webView.getProgress();
195+
return null;
196+
}
197+
167198
public void loadUrl(String url, MethodChannel.Result result) {
168199
if (webView != null) {
169200
webView.loadUrl(url, result);

0 commit comments

Comments
 (0)