flutter_html onLinkTap function giving error

897 Views Asked by At

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<String, String> attributes, element
  ) async {
    onTapFunction();
  },
 );
}

Error from IDE is:

The argument type 'void Function(String?, Map<String, String>, Map<String, String>, dynamic)' can't be assigned to the parameter type 'void Function(String?, Map<String, String>, Element?)?'.dartargument_type_not_assignable

2

There are 2 best solutions below

1
Marcelo Arthur On

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.

0
Sekhar Bhetalam On

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

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