onCreateWindow method
Implementation
Future<bool?> onCreateWindow(
String url,
String? target,
String? windowFeatures,
) async {
Map<String, dynamic> windowFeaturesMap = {};
List<String> features = windowFeatures?.split(",") ?? [];
for (var feature in features) {
var keyValue = feature.trim().split("=");
if (keyValue.length == 2) {
var key = keyValue[0].trim();
var value = keyValue[1].trim();
if (['height', 'width', 'x', 'y'].contains(key)) {
windowFeaturesMap[key] = double.parse(value);
} else {
windowFeaturesMap[key] = value;
}
}
}
final windowId = InAppWebViewManager.windowAutoincrementId;
InAppWebViewManager.windowAutoincrementId++;
final createWindowAction = CreateWindowAction.fromMap({
"windowId": windowId,
"isForMainFrame": true,
"request": {"url": url, "method": "GET"},
"windowFeatures": windowFeaturesMap,
});
InAppWebViewManager.windowActions[windowId] = createWindowAction!;
final handledByClient =
await _channel?.invokeMethod<bool>(
"onCreateWindow",
createWindowAction.toMap(),
) ??
false;
if (!handledByClient &&
InAppWebViewManager.windowActions.containsKey(windowId)) {
InAppWebViewManager.windowActions.remove(windowId);
}
return handledByClient;
}