Closure call with mismatched arguments: function 'call' again

Issue

Exactly one month ago I encountered this problem Closure call with mismatched arguments: function 'call' with js interop.

Now I have the same problem with the SnapSVG library. I’m using it in combination with JsInterop since a moment. Today i tried to use the mouseover function and I get the same exception.

But when I hover the SVG element my function is fired four times :

hover in
hover in
hover in
hover in 
Breaking on exception: Closure call with mismatched arguments: function 'call'

I tried :

var img = s.image("$url", x, y, image.width/2, image.height/2); 
js.FunctionProxy hover = new js.FunctionProxy(() {
  print("hover in");
});

img.mouseover(hover);

and

var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(() {
  print("hover in");
});

This time I checked twice and there is no extra arguments for the callback function.

Solution

Considering the logs you paste, the mouseover handler seems to be called sometimes with parameters sometimes without. To handle that you can use a function with optional parameters :

var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(([p1, p2, p3, p4]) {
  print("hover in");
});

The above callback now handles calls with from 0 to 4 parameters.

Answered By – Alexandre Ardhuin

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *