JSChannelWebViewWrapperDelegate class
An implementation of WebViewWrapperDelegate that allows to inject required CSQ script in the WebView through Javascript channel.
The JavaScript channel should be added through the WebView controller like with the
addJavaScriptChannel
of the package webview_flutter
Usage:
// Using the `WebViewWidget` of `webview_flutter`
// 1. Ensure JavaScript is enabled
webViewController.setJavaScriptMode(JavaScriptMode.unrestricted);
CSQWebViewWrapper(
delegate: JSChannelWebViewWrapperDelegate(
addJavaScriptChannel: (WebViewJSChannelHandler handler) {
// 2. Ensure delegate is properly initialized
webViewController.addJavaScriptChannel(
handler.channelName,
onMessageReceived: (jsMessage) {
handler.onMessageReceived(jsMessage.message);
},
);
},
builder: (context) {
return WebViewWidget(controller: webViewController);
},
),
);
- Implemented types
Constructors
- JSChannelWebViewWrapperDelegate({required AddJSChannelCallback addJavaScriptChannel, required WidgetBuilder builder})
-
Creates an instance of JSChannelWebViewWrapperDelegate used
to inject user script in the WebView.
const
Properties
- addJavaScriptChannel → AddJSChannelCallback
-
Callback executed to add a required JavaScript
channel in the WebView.
final
- builder → WidgetBuilder
-
Builder that will return the WebView widget.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
{required BuildContext context, required String userScriptSource}) → Widget -
Returns the WebView widget that needs to be wrapped.
override
-
initialize(
{required WebViewJSChannelHandler handler}) → void -
Initialize the delegate allowing to execute some
tasks earlier before the build of the WebView widget.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited