【问题标题】:Load html content in flutter web?在flutter web中加载html内容?
【发布时间】:2021-06-11 22:52:18
【问题描述】:

我正在尝试通过 html 内容在 webview 中显示网页。在 android 和 ios 中,flutter_html 运行良好,但在 flutter web 中,此库无法运行。

我也试过这段代码,但没有得到答案:

IFrameElement iframeElement = IFrameElement()
  ..src = 'url'
  ..style.border = 'none'
  ..onLoad.listen((event) {
    // perform you logic here.
  });

ui.platformViewRegistry.registerViewFactory(
  'webpage',
  (int viewId) => iframeElement,
);

return Directionality(
  textDirection: TextDirection.ltr,
  child: Center(
    child: SizedBox(
      width: double.infinity,
      height: double.infinity,
      child: HtmlElementView(viewType: 'webpage'),
    ),
  ),
);

还有其他方法可以在flutter web应用中显示html内容吗?

【问题讨论】:

  • 我正在使用相同的方式在我的网站中显示某些表单,似乎可以正常工作。也许代码审查可以提供帮助?你可以在这里查看源代码github.com/iamSahdeep/portefeuille/blob/master/lib/UI/Screens/… 唯一不同的是我为 HtmlElementView 提供了 Uniquekey 并为 iframeElement 提供了高度/宽度

标签: flutter dart flutter-web


【解决方案1】:

我现在正在使用flutter html在我的应用程序中渲染html内容页面,这是库地址:https://pub.dev/packages/flutter_html。我使用的代码如下所示:

if (item.content != "")
              Html(
                data: item.content,
                style: {
                  "body": Style(
                    fontSize: FontSize(19.0),
                  ),
                },
                onLinkTap: (String? url, RenderContext context, Map<String, String> attributes,  dom.Element? element){
                  CommonUtils.launchUrl(url);
              }),

item.content是我的html网页源代码,希望对你有所帮助。

【讨论】:

  • 正如操作所说,他试图使用这个包,但它不支持 web。
  • 我刚刚意识到它实际上可以在网络上运行,尽管它说它不在 Scores 部分中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-29
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多