【问题标题】:HTML tags in flutter from API来自 API 的 HTML 标签
【发布时间】:2020-03-26 13:47:53
【问题描述】:

我需要显示来自服务器的颤振数据,其中包含一些 HTML 标记。

我使用了flutter_html。 当我在源代码中编写 HTML 标签时它正在工作。 但是当我尝试从 API 显示包含 html 标签的文本时,它不起作用。所有标签都显示在应用程序上。

    Widget textSection = Container(
  padding: const EdgeInsets.only(top:10,right:20,bottom:10,left:28),

  child: Html(
    data: """
      ${event.details} + <p> I am</p>


    """,
    padding: EdgeInsets.all(8.0),
    linkStyle: const TextStyle(
      color: Colors.redAccent,
      decorationColor: Colors.redAccent,
      decoration: TextDecoration.underline,
    ),
    onLinkTap: (url) {
      print("Opening $url...");
    },
    onImageTap: (src) {
      print(src);
    },
    customRender: (node, children) {
      if (node is dom.Element) {
        switch (node.localName) {
          case "custom_tag":
            return Column(children: children);
        }
      }
      return null;
    },
    customTextAlign: (dom.Node node) {
      if (node is dom.Element) {
        switch (node.localName) {
          case "p":
            return TextAlign.justify;
        }
      }
      return null;
    },
    customTextStyle: (dom.Node node, TextStyle baseStyle) {
      if (node is dom.Element) {
        switch (node.localName) {
          case "p":
            return baseStyle.merge(TextStyle(height: 2, fontSize: 20));
        }
      }
      return baseStyle;
    },
  ),
);

输出:

【问题讨论】:

    标签: html flutter dart


    【解决方案1】:

    请在 Html 标签中添加以下行

    useRichText:假

    喜欢:

          Html(
                  """
          ${event.details} + <p> I am</p>
    
    
        """,
     useRichText: false,
        padding: EdgeInsets.all(8.0),
        linkStyle: const TextStyle(
          color: Colors.redAccent,
          decorationColor: Colors.redAccent,
          decoration: TextDecoration.underline,
        ),)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      相关资源
      最近更新 更多