User Registration
At the core of many apps, user accounts have a notion that lets users securely access their information. Parse provides a specialized User class that automatically handles much of the functionality required for user account management. With this class, you’ll be able to add user account functionality to your app.
ParseUser is a subclass of the ParseObject, and has the same features. All the methods that are on ParseObject also exist in ParseUser. The difference is that ParseUser has some special additions specific to user accounts. ParseUser has several properties that set it apart from ParseObject:
- username: The username for the user (required).
- password: The password for the user (required on signup).
- email: The email address for the user (optional).
You are free to use an email address as the username. Ask your users to enter their email, but fill it in the username property — ParseUser will work as normal.
In this guide, you will learn how to use the Flutter plugin for Parse Server to manage users using ParseUser class creating a user registration feature for your Flutter App.
To build a User Registration feature using Parse for a Flutter App.
To complete this tutorial, you will need:
- An Flutter app connected to Back4app.
- Note: Follow the Install Parse SDK on Flutter project to create an Flutter Project connected to Back4App.
- A device (or virtual device) running Android or iOS.
To better understand the SignUp process, we will create an app to register user data and create your account. We won’t explain the Flutter application code once this guide’s primary focus is using the Flutter with Parse. Following the next steps, you will build a Todo App that will store the tasks at Back4App Database.
Following the next steps you will be able to build a Sign App that will create user Account in Back4App Database.
Open your Flutter project from the previous guide Flutter plugin for Parse Server. Go to the main.dart file, clean up all the code, and replace it with:
When debug parameter in function Parse().initialize is true, allows displaying Parse API calls on the console. This configuration can assist in debugging the code. It is advisable to disable debug in the release version.
Find your Application Id and Client Key credentials navigating to your app Dashboard at Back4App Website.
Update your code in main.dart with the values of your project’s ApplicationId and ClientKey in Back4app.
- keyApplicationId = App Id
- keyClientKey = Client Key
Run the project, and the app will load as shown in the image.
The User SignUp function creates a new user in your Parse App. Before that, it checks to make sure that both the username and email are unique. If a SignUp isn’t successful, you should check the error object that is returned. The most likely cause is that another user has already taken the username or email. You should communicate this to your users and ask them to try a different username.
Search for the function doUserRegistration in the file main.dart. Replace the code inside doUserRegistration with:
To build this function, follow these steps:
- Make a new instance of the ParseUser class with the command ParseUser.createUser(username, password, email), with data that were filled in the app.
- Call the signUpfunction, which will register user to your database in the Parse Dashboard.
- Check if user signup with success. If not success, show error description message.
The complete code should look like this:
To test it, click on the Run button in Android Studio/VSCode.
After providing the desired user credentials, you will see this message after pressing on Sign Up if everything was successful:
Error handling can be tested if you try to register a user with the same username as before:
You will get another error if you try to sign up with no password:
- Find your app and click on Dashboard>Core>Browser>User.
At this point, you should see your user as displayed below:
At the end of this guide, you learned how to register new Parse users on Flutter. In the next guide, we will show you how to log in and out users.