/ SDKs / Flutter
SDKs
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Flutter
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

Manage user metadata

Copy link

Metadata consists of key-value items in which you can store additional information to users. You can add up to five key-value items for user metadata. Each key can have up to 128 characters and each value can have up to 190 characters as string. This section explains how to manage user metadata.


Create metadata

Copy link

You can create additional information such as phone number, email address or other descriptions to a user, which can be fetched or rendered into the UI. As an object, user metadata in Map<String, String> is stored into a User object.

To store user metadata into a User object, create Map<String, String> of key-value items, and then pass it as an argument to a parameter when calling the createMetaData method. You can add multiple key-value items in the map.

try {
    final user = sendbird.currentUser();
    final data = ['key1': 'value1', 'key2': 'value2'];
    final createdData = await user.createMetaData(data);
    // A User’s metadata has been created.
} catch (e) {
    // Handle error.
}

Retrieve metadata

Copy link

You can retrieve metadata stored to a user by calling the metaData property of a User object.

final user = sendbird.currentUser();
final metaData = user.metaData;

Update metadata

Copy link

You can update metadata of a user by adding a map of key-value items, and then pass it as an argument to the parameter in the updateMetaData() method. Values of existing keys will be updated and values of new keys will be added. You can put multiple key-value items in the map.

try {
    final user = sendbird.currentUser();
    final data = ['key1': 'valueToUpdate1', 'key2': 'valueToUpdate2'];
    final updatedData = await user.updateMetaData(data);
    // A User’s meta data has been updated.
} catch (e) {
    // Handle error.
}

Delete metadata

Copy link

You can delete metadata stored to a user as below.

try {
    final user = sendbird.currentUser();
    await user.deleteMetaData('key1');
} catch (e) {
    // Handle error.
}