1

I am using Pase.com with js SDK for the backend of my Dart App. This works fine apart from the parse sdk accepts an object of callback functions. In dart Im unsure how to do this, I can get single callbacks working fine. But Im completely lost here.

Normal Parse JS for registering a user

var user = new Parse.User();
  user.set("username", "my name");
  user.set("password", "my pass");
  user.set("email", "[email protected]");

  // other fields can be set just like with Parse.Object
  user.set("phone", "415-392-0202");

  user.signUp(null, {
    success: function(user) {
      // Hooray! Let them use the app now.
    },
    error: function(user, error) {
      // Show the error message somewhere and let the user try again.
      alert("Error: " + error.code + " " + error.message);
    }
  });

My Dart code

void registerSuccess(user) {
    print("success");
  }

  void registerFailed(user, error){
    print("fail");
  }

  void register(String email, String password)
  {
    js.scoped(() {

      var parse = js.context.Parse;


      var parseUser = new js.Proxy(parse.User);

      parseUser.set("username", "my name");
      parseUser.set("password", "my pass");
      parseUser.set("email", "[email protected]");

      print(parseUser.getEmail());

      var callbackSuccess = new js.Callback.once(() => registerSuccess());
      var callbackFailed = new js.Callback.once(() => registerFailed());

      parseUser.signUp(null,{"success":callbackSuccess, "error": callbackFailed});

      //parseUser.signUp();
    });
  }

Also the callback function needs accept vars passed back from the js.

Any help would be a appreciated, I have be spinning my wheels for 2 days on this.

1 Answer 1

4

Instead of :

var callbackSuccess = new js.Callback.once(() => registerSuccess());
var callbackFailed = new js.Callback.once(() => registerFailed());
parseUser.signUp(null,{"success":callbackSuccess, "error": callbackFailed});

use :

var callbackSuccess = new js.Callback.once(registerSuccess);
var callbackFailed = new js.Callback.once(registerFailed);
parseUser.signUp(null, js.map({"success":callbackSuccess, "error": callbackFailed}));
Sign up to request clarification or add additional context in comments.

3 Comments

Now Im getting Uncaught Class '() => void' has no instance method 'call'. NoSuchMethodError : method not found: 'call' Receiver: Closure: (dynamic) => void from Function 'registerFailed':. Arguments: [Instance of 'Proxy', Instance of 'Proxy', Instance of 'Proxy']
You get this error because registerFailed accept only 2 parameters but seams to be called with 3 parameters. You have to change registerFailed to void registerFailed(user, error, WAT).
@AlexandreArdhuin, what library is being used here? I'm not able to find js.scoped and other methods used in this question. dart:js does not have them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.