Set User Properties¶
Description¶
Before updating the BackendlessUser
object you must set new values or new properties locally in the application using the operation described in this topic. Then you have to use the Update User Object operation to send the locally saved data to Backendless servers to update the Users
data table.
Important
When setting or updating a user property, the values must be of "primitive" data types (boolean, string, number, date). To assign a non-primitive value, use the Data relation API .
When registering a new user, the methods below can be used on the new BackendlessUser
object. When updating an existing user, the BackendlessUser
object representing the user must be retrieved from the server (either via login or the data object retrieval APIs).
Method¶
// set property value. The property name is the value of the "key" argument
void setProperty(String key, dynamic value)
// adds properties to the existing ones
void putProperties(Map other)
// removes all existing properties (including the built-in ones such
// as email and password, and sets the provided properties
void setProperties(Map other)
Return Value¶
None.
Example¶
The example below sets a new value "342-821-3802"
for the property "phoneNumber"
locally in the application.
If this property is new and does not exist in the Users
data table, then upon the update operation a new column is created with the specified value. This behavior is available only if the Dynamic Schema Definition option is activated.
// login user and put user object into currentUser variable
var currentUser = await Backendless.userService.login('mylogin@gmail.com', 'my_password');
// set properties
currentUser!
..setProperty('newProperty', propertyValue1) //set one property
..setProperties({'propertyName': propertyValue2}); //set multiple properties
// update user object in database
await Backendless.userService.update(currentUser);