Hi I developed a Flutter Plugin flutter_tex. It's based on the WebView. How do I add Flutter Web support for this??
I tried this example to show my HTML content.
import 'dart:ui' as ui;
void forWeb() {
if(kIsWeb){
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'hello-world-html',
(int viewId) => uni_html.IFrameElement()
..width = '640'
..height = '360'
..src = 'https://www.youtube.com/embed/IyFZznAk69U'
..style.border = 'none');
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: 200,
height: 200,
child: HtmlElementView(viewType: 'hello-world-html'),
),
),
);
}
}
But this code is fine when building for the web but when for compiling on android I get this error even if I am not calling above code.
Compiler message:
../lib/flutter_tex.dart:139:10: Error: Getter not found: 'platformViewRegistry'.
ui.platformViewRegistry.registerViewFactory(
^^^^^^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
You can copy paste run 3 files below
main.dart,mobileui.dartandwebui.dartYou can put
mobileandwebcode in different files and use conditional importThis allow you to have different implement on mobile and web
working demo
when run with
ChromeorAndroid EmulatorinAndroid Studiomain.dart
mobileui.dart
webui.dart