This commit is contained in:
pichillilorenzo 2018-10-23 01:45:42 +02:00
parent 867715ea5e
commit ec348cd8a0
12 changed files with 363 additions and 114 deletions

205
.idea/workspace.xml generated
View File

@ -14,7 +14,20 @@
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="" />
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/main.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.yaml" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" />
<ignored path="$PROJECT_DIR$/.pub/" />
@ -29,7 +42,7 @@
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="DockManager">
<window id="2">
<window id="1">
<content type="file-editors">
<state>
<leaf>
@ -37,8 +50,8 @@
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;MarkdownPreviewEditor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="-1587">
<caret line="44" column="61" lean-forward="true" selection-start-line="44" selection-start-column="61" selection-end-line="44" selection-end-column="61" />
<first_editor relative-caret-position="564">
<caret line="320" column="135" selection-start-line="320" selection-start-column="135" selection-end-line="320" selection-end-column="135" />
</first_editor>
<second_editor>
<markdownNavigatorState />
@ -57,20 +70,21 @@
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="615" column="47" selection-start-line="615" selection-start-column="47" selection-end-line="615" selection-end-column="47" />
<state relative-caret-position="329">
<caret line="798" column="127" lean-forward="true" selection-start-line="798" selection-start-column="15" selection-end-line="798" selection-end-column="127" />
<folding>
<element signature="e#0#50883#0" expanded="true" />
<element signature="e#814#831#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="main.dart" pinned="false" current-in-tab="false">
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="721">
<caret line="254" column="25" selection-start-line="254" selection-start-column="25" selection-end-line="254" selection-end-column="25" />
<state relative-caret-position="233">
<caret line="397" column="18" lean-forward="true" selection-start-line="397" selection-start-column="18" selection-end-line="397" selection-end-column="18" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -78,25 +92,25 @@
</provider>
</entry>
</file>
<file leaf-file-name="CHANGELOG.md" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="split-provider[text-editor;MarkdownPreviewEditor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="45">
<caret line="3" lean-forward="true" selection-start-line="3" selection-end-line="3" />
</first_editor>
<second_editor>
<markdownNavigatorState />
</second_editor>
<file leaf-file-name="index.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="33" selection-end-column="7" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="pubspec.yaml" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="14" selection-start-line="2" selection-start-column="14" selection-end-line="2" selection-end-column="14" />
<file leaf-file-name="CHANGELOG.md" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="split-provider[text-editor;MarkdownPreviewEditor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="30">
<caret line="2" column="58" selection-start-line="2" selection-start-column="58" selection-end-line="2" selection-end-column="58" />
</first_editor>
<second_editor>
<markdownNavigatorState />
</second_editor>
</state>
</provider>
</entry>
@ -112,13 +126,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>MethodChannel</find>
<find>WebViewController</find>
<find>HashMap</find>
<find>String code</find>
<find>flutter_inappwebview</find>
<find>_closeServer</find>
<find>_startS</find>
<find>_throwIsAlreadyOpened</find>
<find>isHidden</find>
<find>shouldOverrideUrlLoading</find>
@ -142,6 +149,13 @@
<find>a</find>
<find>InApp</find>
<find>A [InApp</find>
<find>A `InApp</find>
<find>assets</find>
<find>Ui</find>
<find>postUrl</find>
<find>assert(</find>
<find>sNotEmpty()</find>
<find>loadData</find>
</findStrings>
<replaceStrings>
<replace>activity.getPreferences(0)</replace>
@ -183,11 +197,11 @@
<option value="$PROJECT_DIR$/example/assets/index.html" />
<option value="$PROJECT_DIR$/example/ios/Flutter/Generated.xcconfig" />
<option value="$PROJECT_DIR$/example/pubspec.yaml" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
<option value="$PROJECT_DIR$/pubspec.yaml" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
</list>
</option>
</component>
@ -203,6 +217,19 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope">
<subPane subId="Project Files">
<expand>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="flutter_inappbrowser" type="cbb8eebc:String" user="flutter_inappbrowser" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="AndroidView" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -220,19 +247,6 @@
</subPane>
<option name="show-excluded-files" value="false" />
</pane>
<pane id="Scope">
<subPane subId="Project Files">
<expand>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="flutter_inappbrowser" type="cbb8eebc:String" user="flutter_inappbrowser" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="AndroidView" />
</panes>
</component>
<component name="PropertiesComponent">
@ -401,9 +415,9 @@
<window_info anchor="right" id="Capture Analysis" order="4" />
<window_info anchor="bottom" id="Event Log" order="8" sideWeight="0.5035553" side_tool="true" weight="0.25689086" />
<window_info anchor="bottom" id="Dart Analysis" order="14" weight="0.3276414" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49644473" weight="0.3564568" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49644473" visible="true" weight="0.22838847" />
<window_info anchor="bottom" id="Version Control" order="9" />
<window_info active="true" anchor="bottom" id="Terminal" order="10" sideWeight="0.49644473" visible="true" weight="0.35005337" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.49644473" weight="0.19530416" />
<window_info anchor="right" id="Flutter Outline" order="6" weight="0.32922077" />
<window_info anchor="bottom" id="Logcat" order="11" />
<window_info id="Captures" order="4" weight="0.32936507" />
@ -586,13 +600,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="29" column="29" selection-start-line="29" selection-start-column="29" selection-end-line="29" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/flutter_inappbrowser.iml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
@ -673,26 +680,58 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="721">
<caret line="254" column="25" selection-start-line="254" selection-start-column="25" selection-end-line="254" selection-end-column="25" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pubspec.lock">
<provider selected="true" editor-type-id="text-editor">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="15" column="26" selection-start-line="15" selection-start-column="26" selection-end-line="15" selection-end-column="26" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="33" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="split-provider[text-editor;MarkdownPreviewEditor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="30">
<caret line="2" column="58" selection-start-line="2" selection-start-column="58" selection-end-line="2" selection-end-column="58" />
</first_editor>
<second_editor>
<markdownNavigatorState />
</second_editor>
</state>
</provider>
<provider editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="69" lean-forward="true" selection-start-line="2" selection-start-column="2" selection-end-line="2" selection-end-column="73" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="329">
<caret line="798" column="127" lean-forward="true" selection-start-line="798" selection-start-column="15" selection-end-line="798" selection-end-column="127" />
<folding>
<element signature="e#0#50883#0" expanded="true" />
<element signature="e#814#831#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;MarkdownPreviewEditor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="-1587">
<caret line="44" column="61" lean-forward="true" selection-start-line="44" selection-start-column="61" selection-end-line="44" selection-end-column="61" />
<first_editor relative-caret-position="564">
<caret line="320" column="135" selection-start-line="320" selection-start-column="135" selection-end-line="320" selection-end-column="135" />
</first_editor>
<second_editor>
<markdownNavigatorState />
@ -705,40 +744,16 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="615" column="47" selection-start-line="615" selection-start-column="47" selection-end-line="615" selection-end-column="47" />
<state relative-caret-position="233">
<caret line="397" column="18" lean-forward="true" selection-start-line="397" selection-start-column="18" selection-end-line="397" selection-end-column="18" />
<folding>
<element signature="e#814#831#0" expanded="true" />
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="14" selection-start-line="2" selection-start-column="14" selection-end-line="2" selection-end-column="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="split-provider[text-editor;MarkdownPreviewEditor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="45">
<caret line="3" lean-forward="true" selection-start-line="3" selection-end-line="3" />
</first_editor>
<second_editor>
<markdownNavigatorState />
</second_editor>
</state>
</provider>
<provider editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="69" lean-forward="true" selection-start-line="2" selection-start-column="2" selection-end-line="2" selection-end-column="73" />
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>

View File

@ -1,3 +1,9 @@
## 0.5.2
- fixed some missing `result.success()` on Android and iOS
- added `postUrl()` method for `InAppWebView` and `InAppBrowser`
- added `loadData()` method for `InAppWebView` and `InAppBrowser`
## 0.5.1
- updated README.md

View File

@ -295,7 +295,6 @@ InAppWebView(
}
```
#### Future\<void\> InAppWebViewController.loadUrl
Loads the given `url` with optional `headers` specified as a map from name to value.
@ -304,6 +303,24 @@ Loads the given `url` with optional `headers` specified as a map from name to va
inAppWebViewController.loadUrl(String url, {Map<String, String> headers = const {}});
```
#### Future\<void\> InAppWebViewController.postUrl
Loads the given `url` with `postData` using `POST` method into this WebView.
```dart
inAppWebViewController.postUrl(String url, Uint8List postData);
```
#### Future\<void\> InAppWebViewController.loadData
Loads the given `data` into this WebView, using `baseUrl` as the base URL for the content.
The `mimeType` parameter specifies the format of the data.
The `encoding` parameter specifies the encoding of the data.
```dart
inAppWebViewController.loadData(String data, {String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank"});
```
#### Future\<void\> InAppWebViewController.loadFile
Loads the given `assetFilePath` with optional `headers` specified as a map from name to value.

View File

@ -83,6 +83,25 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
else
result.success(false);
break;
case "postUrl":
if (webView != null)
webView.postUrl(call.argument("url").toString(), (byte[]) call.argument("postData"), result);
else
result.success(false);
break;
case "loadData":
{
String data = call.argument("data").toString();
String mimeType = call.argument("mimeType").toString();
String encoding = call.argument("encoding").toString();
String baseUrl = call.argument("baseUrl").toString();
if (webView != null)
webView.loadData(data, mimeType, encoding, baseUrl, result);
else
result.success(false);
}
break;
case "loadFile":
if (webView != null)
webView.loadFile(call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);

View File

@ -180,6 +180,22 @@ public class InAppBrowserActivity extends AppCompatActivity {
}
}
public void postUrl(String url, byte[] postData, MethodChannel.Result result) {
if (webView != null) {
webView.postUrl(url, postData, result);
} else {
result.error(LOG_TAG, "Cannot load url " + url, null);
}
}
public void loadData(String data, String mimeType, String encoding, String baseUrl, MethodChannel.Result result) {
if (webView != null) {
webView.loadData(data, mimeType, encoding, baseUrl, result);
} else {
result.error(LOG_TAG, "Cannot load data", null);
}
}
public void loadFile(String url, MethodChannel.Result result) {
if (webView != null) {
webView.loadFile(url, result);

View File

@ -137,8 +137,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
if (openWithSystemBrowser) {
Log.d(LOG_TAG, "in system");
openExternal(url, result);
}
else {
} else {
//Load the dialer
if (url.startsWith(WebView.SCHEME_TEL)) {
try {
@ -163,6 +162,18 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "loadUrl":
loadUrl(uuid, call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);
break;
case "postUrl":
postUrl(uuid, call.argument("url").toString(), (byte[]) call.argument("postData"), result);
break;
case "loadData":
{
String data = call.argument("data").toString();
String mimeType = call.argument("mimeType").toString();
String encoding = call.argument("encoding").toString();
String baseUrl = call.argument("baseUrl").toString();
loadData(uuid, data, mimeType, encoding, baseUrl, result);
}
break;
case "loadFile":
loadFile(uuid, call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);
break;
@ -393,6 +404,18 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
}
}
public void postUrl(String uuid, String url, byte[] postData, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.postUrl(url, postData, result);
}
public void loadData(String uuid, String data, String mimeType, String encoding, String baseUrl, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.loadData(data, mimeType, encoding, baseUrl, result);
}
public void loadFile(String uuid, String url, Map<String, String> headers, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null) {

View File

@ -183,7 +183,9 @@ public class InAppWebView extends WebView {
loadUrl(url);
} else {
result.error(LOG_TAG, "url is empty", null);
return;
}
result.success(true);
}
public void loadUrl(String url, Map<String, String> headers, MethodChannel.Result result) {
@ -191,7 +193,24 @@ public class InAppWebView extends WebView {
loadUrl(url, headers);
} else {
result.error(LOG_TAG, "url is empty", null);
return;
}
result.success(true);
}
public void postUrl(String url, byte[] postData, MethodChannel.Result result) {
if (!url.isEmpty()) {
postUrl(url, postData);
} else {
result.error(LOG_TAG, "url is empty", null);
return;
}
result.success(true);
}
public void loadData(String data, String mimeType, String encoding, String baseUrl, MethodChannel.Result result) {
loadDataWithBaseURL(baseUrl, data, mimeType, encoding, null);
result.success(true);
}
public void loadFile(String url, MethodChannel.Result result) {
@ -206,7 +225,9 @@ public class InAppWebView extends WebView {
loadUrl(url);
} else {
result.error(LOG_TAG, "url is empty", null);
return;
}
result.success(true);
}
public void loadFile(String url, Map<String, String> headers, MethodChannel.Result result) {
@ -221,7 +242,9 @@ public class InAppWebView extends WebView {
loadUrl(url, headers);
} else {
result.error(LOG_TAG, "url is empty", null);
return;
}
result.success(true);
}
public boolean isLoading() {

View File

@ -1,5 +1,5 @@
import 'dart:async';
import 'dart:convert' show base64;
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
@ -7,9 +7,9 @@ class MyInAppBrowser extends InAppBrowser {
@override
Future onLoadStart(String url) async {
print("\n\nStarted $url\n\n");
print("\n\n ${await this.isHidden()} \n\n");
print(await this.webViewController.canGoBack());
print(await this.webViewController.canGoForward());
// print("\n\n ${await this.isHidden()} \n\n");
// print(await this.webViewController.canGoBack());
// print(await this.webViewController.canGoForward());
}
@override
@ -105,7 +105,7 @@ class MyInAppBrowser extends InAppBrowser {
@override
void onProgressChanged(int progress) {
print("Progress: $progress");
// print("Progress: $progress");
}
@override
@ -117,6 +117,47 @@ class MyInAppBrowser extends InAppBrowser {
void shouldOverrideUrlLoading(String url) {
print("\n\n override $url\n\n");
this.webViewController.loadUrl(url);
// var postData = "username=my_username&password=my_password";
// inAppBrowserFallback.webViewController.postUrl("http://localhost:8080", utf8.encode(postData));
// var htmlData = """
//<!doctype html>
//<html lang="en">
//<head>
// <meta charset="UTF-8">
// <meta name="viewport"
// content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
// <meta http-equiv="X-UA-Compatible" content="ie=edge">
// <title>Document</title>
// <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
// <link rel="stylesheet" href="http://localhost:8080/assets/css/style.css">
// <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
//</head>
//<body>
//<div class="container">
// <div class="container">
// <img src="http://localhost:8080/assets/images/dart.svg" alt="dart logo">
// <div class="row">
// <div class="col-sm">
// One of three columns
// </div>
// <div class="col-sm">
// One of three columns
// </div>
// <div class="col-sm">
// One of three columns
// </div>
// </div>
// </div>
// <script>
// console.log("hello");
// </script>
//</div>
//</body>
//</html>
// """;
// inAppBrowserFallback.webViewController.loadData(htmlData);
}
@override
@ -231,10 +272,10 @@ class _MyAppState extends State<MyApp> {
// });
//
await inAppBrowserFallback.open(url: "https://flutter.io/", options: {
"useOnLoadResource": true,
//"useOnLoadResource": true,
//"hidden": true,
//"toolbarTopFixedTitle": "Fixed title",
//"useShouldOverrideUrlLoading": true
"useShouldOverrideUrlLoading": true
//"hideUrlBar": true,
//"toolbarTop": false,
//"toolbarBottom": false

View File

@ -378,6 +378,34 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
webView.load(request)
}
func loadData(data: String, mimeType: String, encoding: String, baseUrl: String) {
let url = URL(string: baseUrl)!
currentURL = url
if #available(iOS 9.0, *) {
webView.load(data.data(using: .utf8)!, mimeType: mimeType, characterEncodingName: encoding, baseURL: url)
} else {
webView.loadHTMLString(data, baseURL: url)
}
}
func postUrl(url: URL, postData: Data, result: @escaping FlutterResult) {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { (data : Data?, response : URLResponse?, error : Error?) in
var returnString = ""
if data != nil {
returnString = String(data: data!, encoding: .utf8) ?? ""
}
DispatchQueue.main.async(execute: {() -> Void in
self.webView.loadHTMLString(returnString, baseURL: url)
result(true)
})
}
task.resume()
}
// Load user requested url
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()

View File

@ -68,6 +68,12 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
case "loadUrl":
self.loadUrl(uuid: uuid, arguments: arguments!, result: result)
break
case "loadData":
self.loadData(uuid: uuid, arguments: arguments!, result: result)
break
case "postUrl":
self.postUrl(uuid: uuid, arguments: arguments!, result: result)
break
case "loadFile":
self.loadFile(uuid: uuid, arguments: arguments!, result: result)
break
@ -384,10 +390,34 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
}
else {
result(FlutterError(code: "InAppBrowserFlutterPlugin", message: "url is empty", details: nil))
return
}
result(true)
}
public func loadData(uuid: String, arguments: NSDictionary, result: @escaping FlutterResult) {
let webViewController: InAppBrowserWebViewController = self.webViewControllers[uuid] as! InAppBrowserWebViewController
let data = (arguments["data"] as? String)!
let mimeType = (arguments["mimeType"] as? String)!
let encoding = (arguments["encoding"] as? String)!
let baseUrl = (arguments["baseUrl"] as? String)!
webViewController.loadData(data: data, mimeType: mimeType, encoding: encoding, baseUrl: baseUrl)
result(true)
}
public func postUrl(uuid: String, arguments: NSDictionary, result: @escaping FlutterResult) {
let webViewController: InAppBrowserWebViewController = self.webViewControllers[uuid] as! InAppBrowserWebViewController
if let url = arguments["url"] as? String {
let postData = (arguments["postData"] as? FlutterStandardTypedData)!
let absoluteUrl = URL(string: url)!.absoluteURL
webViewController.postUrl(url: absoluteUrl, postData: postData.data, result: result)
}
else {
result(FlutterError(code: "InAppBrowserFlutterPlugin", message: "url is empty", details: nil))
return
}
}
public func loadFile(uuid: String, arguments: NSDictionary, result: @escaping FlutterResult) {
let webViewController: InAppBrowserWebViewController = self.webViewControllers[uuid] as! InAppBrowserWebViewController
if let url = arguments["url"] as? String {
@ -404,6 +434,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
}
else {
result(FlutterError(code: "InAppBrowserFlutterPlugin", message: "url is empty", details: nil))
return
}
result(true)
}
@ -458,6 +489,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
func open(inSystem url: URL, result: @escaping FlutterResult) {
if !UIApplication.shared.canOpenURL(url) {
result(FlutterError(code: "InAppBrowserFlutterPlugin", message: url.absoluteString + " cannot be opened!", details: nil))
return
}
else {
if #available(iOS 10.0, *) {

View File

@ -189,7 +189,7 @@ class InAppBrowser {
/// - __allowsPictureInPictureMediaPlayback__: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
/// - __spinner__: Set to `false` to hide the spinner when the WebView is loading a page. The default value is `true`.
Future<void> open({String url = "about:blank", Map<String, String> headers = const {}, Map<String, dynamic> options = const {}}) async {
assert(url != null);
assert(url != null && url.isNotEmpty);
this._throwIsAlreadyOpened(message: 'Cannot open $url!');
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
@ -233,7 +233,7 @@ class InAppBrowser {
///...
///```
Future<void> openFile(String assetFilePath, {Map<String, String> headers = const {}, Map<String, dynamic> options = const {}}) async {
assert(assetFilePath != null);
assert(assetFilePath != null && assetFilePath.isNotEmpty);
this._throwIsAlreadyOpened(message: 'Cannot open $assetFilePath!');
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
@ -249,7 +249,7 @@ class InAppBrowser {
///This is a static method that opens an [url] in the system browser. You wont be able to use the [InAppBrowser] methods here!
static Future<void> openWithSystemBrowser(String url) async {
assert(url != null);
assert(url != null && url.isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => "");
args.putIfAbsent('url', () => url);
@ -441,7 +441,7 @@ class ChromeSafariBrowser {
///- __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
///- __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
Future<void> open(String url, {Map<String, dynamic> options = const {}, Map<String, String> headersFallback = const {}, Map<String, dynamic> optionsFallback = const {}}) async {
assert(url != null);
assert(url != null && url.isNotEmpty);
this._throwIsAlreadyOpened(message: 'Cannot open $url!');
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid);
@ -768,7 +768,7 @@ class InAppWebViewController {
///Loads the given [url] with optional [headers] specified as a map from name to value.
Future<void> loadUrl(String url, {Map<String, String> headers = const {}}) async {
assert(url != null);
assert(url != null && url.isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
if (_inAppBrowserUuid != null) {
_inAppBrowser._throwIsNotOpened(message: 'Cannot laod $url!');
@ -779,6 +779,37 @@ class InAppWebViewController {
await _channel.invokeMethod('loadUrl', args);
}
///Loads the given [url] with [postData] using `POST` method into this WebView.
Future<void> postUrl(String url, Uint8List postData) async {
assert(url != null && url.isNotEmpty);
assert(postData != null);
Map<String, dynamic> args = <String, dynamic>{};
if (_inAppBrowserUuid != null) {
_inAppBrowser._throwIsNotOpened(message: 'Cannot laod $url!');
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
}
args.putIfAbsent('url', () => url);
args.putIfAbsent('postData', () => postData);
await _channel.invokeMethod('postUrl', args);
}
///Loads the given [data] into this WebView, using [baseUrl] as the base URL for the content.
///The [mimeType] parameter specifies the format of the data.
///The [encoding] parameter specifies the encoding of the data.
Future<void> loadData(String data, {String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank"}) async {
assert(data != null);
Map<String, dynamic> args = <String, dynamic>{};
if (_inAppBrowserUuid != null) {
_inAppBrowser._throwIsNotOpened();
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
}
args.putIfAbsent('data', () => data);
args.putIfAbsent('mimeType', () => mimeType);
args.putIfAbsent('encoding', () => encoding);
args.putIfAbsent('baseUrl', () => baseUrl);
await _channel.invokeMethod('loadData', args);
}
///Loads the given [assetFilePath] with optional [headers] specified as a map from name to value.
///
///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!
@ -809,7 +840,7 @@ class InAppWebViewController {
///...
///```
Future<void> loadFile(String assetFilePath, {Map<String, String> headers = const {}}) async {
assert(assetFilePath != null);
assert(assetFilePath != null && assetFilePath.isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
if (_inAppBrowserUuid != null) {
_inAppBrowser._throwIsNotOpened(message: 'Cannot laod $assetFilePath!');
@ -1064,8 +1095,6 @@ class InAppLocalhostServer {
}
}
print(contentType);
request.response.headers.contentType = new ContentType(contentType[0], contentType[1], charset: 'utf-8');
request.response.add(body);
request.response.close();

View File

@ -1,6 +1,6 @@
name: flutter_inappbrowser
description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window. (inspired by the popular cordova-plugin-inappbrowser).
version: 0.5.1
version: 0.5.2
author: Lorenzo Pichilli <pichillilorenzo@gmail.com>
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser