registerWith static method
Implementation
static void registerWith(Registrar registrar) {
methodChannel = MethodChannel(
'enx_flutter_plugin',
const StandardMethodCodec(),
registrar,
);
if (kIsWeb) {
ui_web.platformViewRegistry.registerViewFactory("EnxPlayer", (int viewId,
{Object? params}) {
Map<String, dynamic> jsonMap =
jsonDecode(jsonEncode(params).toString());
int uid = jsonMap['setZOrderMediaOverlay']['uid'];
// Check if the view is already registered
if (registeredViews.containsKey(uid)) {
// If already registered, return the existing HTML element
return registeredViews[uid]!;
} else {
// Create a new HTML element
final html.Element htmlElement = html.DivElement()
..id = '$uid'
..style.width = '100%'
..style.height = '100%';
// Add the element to the document body
html.document.body!.append(htmlElement);
// Store the element in the map
registeredViews[uid] = htmlElement;
// Call JavaScript method to create native view
js.context.callMethod("createNativeView", [uid]);
// Return an object representing the platform view (in this case, return the HTML element)
return htmlElement;
}
});
final EnxFlutterPluginWeb instance = EnxFlutterPluginWeb();
methodChannel.setMethodCallHandler(instance.handleMethodCall);
}
}