flutter_html中的onLinkTap函数出现错误。

huangapple go评论69阅读模式
英文:

flutter_html onLinkTap function giving error

问题

以下是翻译好的部分:

我是Flutter的新手,正在使用flutter_html的版本flutter_html^3.0.0-beta.2构建HTML小部件。随着最近的版本更新,我在onLinkTap函数上遇到了一个错误。

以下是代码:

static Widget getHTMLWidget(String htmlContent, Function onTap) {
  return Html(
    shrinkWrap: true,
    data: htmlContent,
    onLinkTap: (
      String? url, 
      RenderContext renderContext,
      Map<String, String> attributes, element
    ) async {
      onTapFunction();
    },
  );
}

IDE中的错误信息是:

“参数类型'void Function(String?, Map<String, String>, Map<String, String>, dynamic)'无法分配给参数类型'void Function(String?, Map<String, String>, Element?)?'。”

英文:

I am new to Flutter and working on build html widget using flutter_html with version flutter_html^3.0.0-beta.2. With the recent version updates I am getting one error for onLinkTap function.

Following is the code:

static Widget getHTMLWidget(String htmlContent, Function onTap) {
 return Html(
  shrinkWrap: true,
  data: htmlContent,
  onLinkTap: (
    String? url, 
    RenderContext renderContext,
    Map&lt;String, String&gt; attributes, element
  ) async {
    onTapFunction();
  },
 );
}

Error from IDE is:

The argument type &#39;void Function(String?, Map&lt;String, String&gt;, Map&lt;String, String&gt;, dynamic)&#39; can&#39;t be assigned to the parameter type &#39;void Function(String?, Map&lt;String, String&gt;, Element?)?&#39;.dartargument_type_not_assignable

答案1

得分: 1

这个版本还没有准备好投入生产使用。可能是因为文档还没有准备好。

根据 dart.pub 上的文档,这个包的最新发布版本是 flutter_html: ^2.2.1您可以在这里检查

如果之前可以正常工作,可能是这个方法的参数已经更改了,没有文档我们就不知道。如果您真的需要测试这个 beta 版本,请尝试在他们的 GitHub 存储库上提出问题。

英文:

This version isn't ready for production. It's probably that the documentation isn't ready yet.

The latest release version of this package is flutter_html: ^2.2.1 according to the docs on dart.pub as you can check here

And if this worked before, maybe the arguments of this method were changed and we couldn't know without the docs. If you really need to test this beta version, try to open an Issue on their Github Repository.

答案2

得分: 0

根据最新版本的代码更改,我们需要按照以下方式调用该函数:

Html(
  shrinkWrap: true,
  data: htmlContent,
  onLinkTap: (url, _, __) {
    onTapFunction();
  }
);
英文:

As per the latest version code changes we need to call the function like below,

Html(
 shrinkWrap: true,
 data: htmlContent,
 onLinkTap: (url, _, __) {
  onTapFunction();
 }
);

huangapple
  • 本文由 发表于 2023年6月16日 00:14:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定