onMethodCall static method
An internal property that users should not use. A handler that handles method calls coming from the native side.
Implementation
static Future<bool?> onMethodCall(MethodCall call) async {
/// Get the webview instance corresponding to webviewId
WebViewLinuxPlatformController _getControllerByWebviewId(int webviewId) {
final controller = instanceManager.getInstance(webviewId)
as WebViewLinuxPlatformController?;
if (controller == null) {
throw 'WebView with webviewId=$webviewId is not found';
}
return controller;
}
switch (call.method) {
case 'javascriptChannelMessage':
// javascriptChannels have not yet been implemented.
// TODO(Ino): implement javascriptChannels
throw UnimplementedError('javascriptChannelMessage is not implemented');
case 'navigationRequest':
// TODO(Ino): implement navigationDelegate
// WebViewLinuxPlatformController controller = _getController(call);
// return await controller.callbacksHandler.onNavigationRequest(
// url: call.arguments['url'] as String,
// isForMainFrame: call.arguments['isForMainFrame'] as bool,
// );
throw UnimplementedError('navigationRequest is not implemented');
case 'javascriptResult':
// The result of _runJavascriptInternal comes here.
final int jsRunId = call.arguments['jsRunId'] as int;
final bool wasExecuted = call.arguments['wasExecuted'] as bool;
final bool isException = call.arguments['isException'] as bool;
final String result = call.arguments['result'] as String;
final bool isUndefined = call.arguments['isUndefined'] as bool;
log.fine('javascriptResult received!:\n'
' jsRunId: $jsRunId\n'
' wasExecuted: $wasExecuted\n'
' isException: $isException\n'
' result: $result\n'
' isUndefined: $isUndefined');
// complete the waiting completer
if (_jsCompleters[jsRunId] != null) {
_jsCompleters[jsRunId]!.complete(_JavascriptResult(
wasExecuted: wasExecuted,
isException: isException,
result: result,
isUndefined: isUndefined));
_jsCompleters.remove(jsRunId);
} else {
log.warning('The js completer for jsRunId=$jsRunId does not exist');
}
return true;
case 'onPageFinished':
WebViewLinuxPlatformController controller =
_getControllerByWebviewId(call.arguments['webviewId'] as int);
controller.callbacksHandler
.onPageFinished(call.arguments['url'] as String);
return null;
case 'onProgress':
WebViewLinuxPlatformController controller =
_getControllerByWebviewId(call.arguments['webviewId'] as int);
controller.callbacksHandler
.onProgress(call.arguments['progress'] as int);
return null;
case 'onPageStarted':
WebViewLinuxPlatformController controller =
_getControllerByWebviewId(call.arguments['webviewId'] as int);
controller.callbacksHandler
.onPageStarted(call.arguments['url'] as String);
return null;
case 'onWebResourceError':
WebViewLinuxPlatformController controller =
_getControllerByWebviewId(call.arguments['webviewId']);
controller.callbacksHandler.onWebResourceError(
WebResourceError(
errorCode: call.arguments['errorCode'] as int,
description: call.arguments['description'] as String,
failingUrl: call.arguments['failingUrl'] as String?,
// TODO(Ino): support domain
domain: call.arguments['domain'] as String?,
// TODO(Ino): support errorType
errorType: call.arguments['errorType'] == null
? null
: WebResourceErrorType.values.firstWhere(
(WebResourceErrorType type) {
return type.toString() ==
'$WebResourceErrorType.${call.arguments['errorType']}';
},
),
),
);
return null;
}
throw MissingPluginException(
'${call.method} was invoked but has no handler');
}