1

Based on:

How do I create an anonymous JavaScript function/callback with Dart's JS interop?

I have written this Dart function:

fadeIn(String selector) {

    Completer completer = new Completer();

    context.callMethod("\$", [selector]).callMethod("fadeIn", [FADE_SPEED, () {
        print("callback");
        completer.complete();
    }]);

    return completer.future;

}

Which should do (in JavaScript) $(selector).fadeIn( FADE_SPEED, function() { console.log("bacllback");.

However, when running this function in Dartium, I get the following exception:

Exception: type '() => dynamic' is not a subtype of type '(dynamic) => dynamic' of 'f'.

I don't understand the Exception. What have I done wrong?

The message "callback" does get printed out to the console though.

1 Answer 1

0

I think you need to add an argument to the following callback

change

[FADE_SPEED, () {

to

[FADE_SPEED, (e) {

Often the underscore is used to indicate that the argument should be ignored

[FADE_SPEED, (_) {

The error message indicates that one argument was provided but the provided callback method accepts none.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.