callbackdartdart-js-interop

Closure call with mismatched arguments: function 'call'


I'm using the (2.0)js-interop library in combination with the JS library ImageLoaded and I'm stuck the FunctionProxy class because the code below throw the following error:

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

js.FunctionProxy loaded = new js.FunctionProxy((){
      print("called");
      js.Proxy pckry = new js.Proxy(context.Packery, container, options);
    });
    
js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);

Which is weird because my js callback is called 5 times before the app crashes.


Solution

  • Looking at the Usage section of imagesLoaded it looks like the callback takes one parameter. So you have to add this parameter to your callback :

    js.FunctionProxy loaded = new js.FunctionProxy((instance) {
      print("called");
      js.Proxy pckry = new js.Proxy(context.Packery, container, options);
    });
    
    js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);
    

    Additional notes :

    Thus, you should be able to use :

    final img = context.imagesLoaded(container, (instance) {
      print("called");
      js.Proxy pckry = new js.Proxy(context.Packery, container, options);
    });