Flutter flutter_html 包不适用于 api

问题描述 投票:0回答:1
Html(
                                        data: """
        ${cubit.umrapages![cubit.currentPageIndex].content}
        """,
                                        extensions: [
                                           IframeHtmlExtension(),
                                        ],
                                        style: {
                                          "p.fancy": Style(
                                            textAlign: TextAlign.center,
                                            backgroundColor: Colors.grey,
                                            margin: Margins(
                                                left: Margin(50, Unit.px),
                                                right: Margin.auto()),
                                            width: Width(300, Unit.px),
                                            fontWeight: FontWeight.bold,
                                          ),
                                        },
                                      ),

这是我的 Flutter 代码,当我传递静态 html 字符串时,它接受它,但无法转换来自 api 的 html 代码。我有 flutter_html: ^3.0.0-beta.2 版本,它没有 useRichText 功能,我该怎么办?

我尝试过其他 Html 打包,但没有成功

html css flutter webview flutter-html
1个回答
0
投票

确保从 API 接收的 HTML 内容格式正确且有效。您可以使用在线 HTML 验证器来检查 HTML 代码中是否有任何语法错误或问题。

有时,来自 API 的 HTML 内容可能包含编码实体(例如,“<' for '<', '>”代表“>”)。确保在将 HTML 内容传递到 Html 小部件之前对这些实体进行解码。

如果问题仍然存在,您可以考虑尝试使用替代包在 Flutter 中渲染 HTML,例如“webview_flutter”或“html”。

© www.soinside.com 2019 - 2024. All rights reserved.