Search code examples
flutterflutter-dependenciesparse-serverback4app

How to set additional required fields on back4app user object in flutter


I am using parse_server_sdk in flutter mobile to signup a user in an app. Ideally, you can call the ParseUser.createUser(username, password, email) function to do this. My question is that I have added columns firstname and lastname to the User class via back4app console so my users have additional fields besides what is provided out of the box. I intend to make these columns required which means they need to be set when a user is created in the app. The problem is I cannot find (or I am unaware of) a function within ParseUser that allows you to include other parameters beyond username, password and email. My current workaround is to:

  • Make the columns not required
  • First create the user in the app
  • Then, immediately turn around and update the user object with values for the added columns
  • Save the user object again in the same flow

It just seems a bit awkward to do it this way. Is there a more straightforward way to do this that I haven't considered?


Solution

  • The following code should work:

    final user = ParseUser.createUser(username, password, email)
      ..set('firstname', firstname)
      ..set('lastname', lastname);
    await user.signUp();