Commit 219f079a authored by pichillilorenzo's avatar pichillilorenzo

Fixed README.md and method documentation

parent 23194ac6
This diff is collapsed.
## 1.1.1
- Fixed README.md and `addJavaScriptHandler` method documentation
## 1.1.0 ## 1.1.0
- Breaking change for `addJavaScriptHandler` and `removeJavaScriptHandler` methods. - Breaking change for `addJavaScriptHandler` and `removeJavaScriptHandler` methods.
......
...@@ -575,18 +575,30 @@ that can be used to get the json result returned by `JavaScriptHandlerCallback`. ...@@ -575,18 +575,30 @@ that can be used to get the json result returned by `JavaScriptHandlerCallback`.
In this case, simply return data that you want to send and it will be automatically json encoded using `jsonEncode` from the `dart:convert` library. In this case, simply return data that you want to send and it will be automatically json encoded using `jsonEncode` from the `dart:convert` library.
So, on the JavaScript side, to get data coming from the Dart side, you will use: So, on the JavaScript side, to get data coming from the Dart side, you will use:
```javascript ```html
window.addEventListener("flutterInAppBrowserPlatformReady", function(event) { <script>
window.flutter_inappbrowser.callHandler('handlerFoo').then(function(result) { window.addEventListener("flutterInAppBrowserPlatformReady", function(event) {
console.log(result, typeof result); window.flutter_inappbrowser.callHandler('handlerFoo').then(function(result) {
console.log(JSON.stringify(result)); console.log(result, typeof result);
console.log(JSON.stringify(result));
});
window.flutter_inappbrowser.callHandler('handlerFooWithArgs', 1, true, ['bar', 5], {foo: 'baz'}).then(function(result) {
console.log(result, typeof result);
console.log(JSON.stringify(result));
});
}); });
</script>
```
window.flutter_inappbrowser.callHandler('handlerFooWithArgs', 1, true, ['bar', 5], {foo: 'baz'}).then(function(result) { Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
console.log(result, typeof result); ```dart
console.log(JSON.stringify(result)); // Inject JavaScript that will receive data back from Flutter
}); inAppWebViewController.injectScriptCode("""
}); window.flutter_inappbrowser.callHandler('test', 'Text from Javascript').then(function(result) {
console.log(result);
});
""");
``` ```
```dart ```dart
...@@ -599,7 +611,7 @@ Removes a JavaScript message handler previously added with the `addJavaScriptHan ...@@ -599,7 +611,7 @@ Removes a JavaScript message handler previously added with the `addJavaScriptHan
Returns the value associated with `handlerName` before it was removed. Returns the value associated with `handlerName` before it was removed.
Returns `null` if `handlerName` was not found. Returns `null` if `handlerName` was not found.
```dart ```dart
inAppWebViewController.removeJavaScriptHandler(String handlerName, int index); inAppWebViewController.removeJavaScriptHandler(String handlerName);
``` ```
#### Future\<Uint8List\> InAppWebViewController.takeScreenshot #### Future\<Uint8List\> InAppWebViewController.takeScreenshot
......
...@@ -1177,7 +1177,8 @@ class InAppWebViewController { ...@@ -1177,7 +1177,8 @@ class InAppWebViewController {
///In this case, simply return data that you want to send and it will be automatically json encoded using [jsonEncode] from the `dart:convert` library. ///In this case, simply return data that you want to send and it will be automatically json encoded using [jsonEncode] from the `dart:convert` library.
/// ///
///So, on the JavaScript side, to get data coming from the Dart side, you will use: ///So, on the JavaScript side, to get data coming from the Dart side, you will use:
///```javascript ///```html
///<script>
/// window.addEventListener("flutterInAppBrowserPlatformReady", function(event) { /// window.addEventListener("flutterInAppBrowserPlatformReady", function(event) {
/// window.flutter_inappbrowser.callHandler('handlerFoo').then(function(result) { /// window.flutter_inappbrowser.callHandler('handlerFoo').then(function(result) {
/// console.log(result, typeof result); /// console.log(result, typeof result);
...@@ -1189,6 +1190,17 @@ class InAppWebViewController { ...@@ -1189,6 +1190,17 @@ class InAppWebViewController {
/// console.log(JSON.stringify(result)); /// console.log(JSON.stringify(result));
/// }); /// });
/// }); /// });
///</script>
///```
///
///Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
///```dart
/// // Inject JavaScript that will receive data back from Flutter
/// inAppWebViewController.injectScriptCode("""
/// window.flutter_inappbrowser.callHandler('test', 'Text from Javascript').then(function(result) {
/// console.log(result);
/// });
/// """);
///``` ///```
void addJavaScriptHandler(String handlerName, JavaScriptHandlerCallback callback) { void addJavaScriptHandler(String handlerName, JavaScriptHandlerCallback callback) {
this.javaScriptHandlersMap[handlerName] = (callback); this.javaScriptHandlersMap[handlerName] = (callback);
......
name: flutter_inappbrowser 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). 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: 1.1.0 version: 1.1.1
author: Lorenzo Pichilli <pichillilorenzo@gmail.com> author: Lorenzo Pichilli <pichillilorenzo@gmail.com>
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser homepage: https://github.com/pichillilorenzo/flutter_inappbrowser
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment