Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/epoll-j/bridge_webview_flutter
Add jsbridge to the webview
https://github.com/epoll-j/bridge_webview_flutter
flutter flutter-plugin jsbridge-webview webview webview-library
Last synced: 3 months ago
JSON representation
Add jsbridge to the webview
- Host: GitHub
- URL: https://github.com/epoll-j/bridge_webview_flutter
- Owner: epoll-j
- License: bsd-3-clause
- Created: 2020-04-15T09:20:02.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-10T06:37:29.000Z (over 4 years ago)
- Last Synced: 2023-08-20T21:29:11.753Z (over 1 year ago)
- Topics: flutter, flutter-plugin, jsbridge-webview, webview, webview-library
- Language: Dart
- Homepage:
- Size: 155 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
这个库不再维护了,因为跟webview耦合度太高了,把jsbridge内容分离出来重写了一个[plugin](https://github.com/epoll-j/flutter_jsbridge_plugin)
# Add JsBridge to the WebView[A Flutter plugin that provides a JsBridge on WebView widget.](https://pub.dev/packages/bridge_webview_flutter)
On iOS the WebView widget is backed by a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview);
On Android the WebView widget is backed by a [WebView](https://developer.android.com/reference/android/webkit/WebView).This plugin based on the [webview_flutter](https://pub.dev/packages/webview_flutter)
## Developers Preview Status
To use this plugin on iOS you need to opt-in for the embedded views preview by
adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview`
and the value `YES`.## Keyboard support - not ready for production use
Keyboard support within webviews is experimental. The Android version relies on some low-level knobs that have not been well tested
on a broad spectrum of devices yet, and therefore **it is not recommended to rely on webview keyboard in production apps yet**.
See the [webview-keyboard](https://github.com/flutter/flutter/issues?q=is%3Aopen+is%3Aissue+label%3A%22p%3A+webview-keyboard%22) for known issues with keyboard input.## Setup
### iOS
Opt-in to the embedded views preview by adding a boolean property to the app's `Info.plist` file
with the key `io.flutter.embedded_views_preview` and the value `YES`.## Usage
Add `bridge_webview_flutter` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).```
BridgeWebView(
initialUrl: 'https://flutter.dev',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
webViewController.registerHandler("methodName", response: "r1", onCallBack: (callBackData) {
print(callBackData.name); // handler name
print(callBackData.data); // callback data ({'param': '1'})
});
webViewController.callHandler("methodName", data: "sendData", onCallBack: (callBackData) {
print(callBackData.name); // handler name
print(callBackData.data); // callback data (r2)
});
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
}
)
```### Register a Flutter handler function so that js can call
```
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
webViewController.registerHandler("methodName", response: "r1", onCallBack: (callBackData) {
print(callBackData.name); // handler name
print(callBackData.data); // callback data ({'param': '1'})
});
}
```
#### js can call this handler method "methodName" through:
```
WebViewJavascriptBridge.callHandler(
'methodName'
, {'param': '1'}
, function(data) {
// data is r1
}
);
```### Register a JavaScript handler function so that flutter can call
```
WebViewJavascriptBridge.registerHandler("methodName", function(data, responseCallback) {
// data is 'sendData'
responseCallback('r2');
});
```
#### flutter can call this js handler function "methodName" through:
```
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
webViewController.callHandler("methodName", data: "sendData", onCallBack: (callBackData) {
print(callBackData.name); // handler name
print(callBackData.data); // callback data (r2)
});
}
```