MethodChannelWebviewWinFloating constructor
MethodChannelWebviewWinFloating()
Implementation
MethodChannelWebviewWinFloating() {
assert(() {
// When hot-reload in debugging mode, clear all old webviews created before hot-reload
methodChannel.invokeMethod<bool>('clearAll');
return true;
}());
methodChannel.setMethodCallHandler((call) async {
//log("[webview] native->flutter: $call");
int? webviewId = call.arguments["webviewId"];
assert(webviewId != null);
final ref = webviewMap[webviewId];
if (ref == null) {
log("webview not found: id = $webviewId");
return;
}
final controller = ref.target;
if (controller == null) {
webviewMap.remove(webviewId);
log("webview is alive but not referenced anymore: id = $webviewId");
return;
}
if (call.method == "OnWebMessageReceived") {
String message = call.arguments["message"]!;
controller.notifyMessageReceived_(message);
} else if (call.method == "onPageStarted") {
String url = call.arguments["url"]!;
bool isNewWindow = call.arguments["isNewWindow"]!;
bool isUserInitiated = call.arguments["isUserInitiated"]!;
controller.notifyOnPageStarted_(url, isNewWindow, isUserInitiated);
} else if (call.method == "onPageFinished") {
String url = call.arguments["url"]!;
int errCode = call.arguments["errCode"]!;
controller.notifyOnPageFinished_(url, errCode);
} else if (call.method == "onPageTitleChanged") {
String title = call.arguments["title"]!;
controller.notifyOnPageTitleChanged_(title);
} else if (call.method == "onMoveFocusRequest") {
bool isNext = call.arguments["isNext"]!;
controller.notifyOnFocusRequest_(isNext);
} else if (call.method == "OnFullScreenChanged") {
bool? isFullScreen = call.arguments["isFullScreen"];
assert(isFullScreen != null);
controller.notifyFullScreenChanged_(isFullScreen!);
} else if (call.method == "onHistoryChanged") {
controller.notifyHistoryChanged_();
} else {
assert(false, "unknown call from native: ${call.method}");
}
});
}