【发布时间】:2020-05-21 08:25:39
【问题描述】:
您好,我开发了一个 Flutter 插件 flutter_tex。它基于 WebView。如何为此添加 Flutter Web 支持?
我尝试了这个示例来显示我的 HTML 内容。
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'),
),
),
);
}
}
但是这个代码在为 web 构建时很好,但是在 android 上编译时,即使我没有调用上面的代码,我也会收到这个错误。
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.
【问题讨论】:
标签: flutter flutter-web dart-html dart-webui