Chat / Flutter
Current version: v3
Chat Flutter v3
Chat Flutter
Chat
Flutter
Home
/
Chat
/
Flutter
/
Channel

Manage channel metadata

You can store additional information to channels such as background color or channel description with channel metadata, which can be fetched or rendered into the UI. Channel metadata is Map<String, String> and it can be stored into a Channel object.


Create metadata

To store channel metadata into a channel object, create a new object of key-value items in which the data type of the key and value is Map<String, String>. Then, pass the object as an argument to a parameter when calling the createMetaData() method. You can put multiple key-value items in the dictionary.

try {
    final createdMetaData = await channel.createMetaData(
        {'key1': 'value1', 'key2': 'value2'}
    );
    // Channel metadata is created.
} catch (e) {
    // Handle error.
}

Update metadata

The process of updating channel metadata is the same as creating one. Values of existing keys can be updated and values of new keys can be added by calling the updateMetaData method.

try {
    final updatedMetaData = await channel.updateMetaData({
        'key1': 'valueToUpdate1', // Update an existing item with new value.
        'key2': 'valueToUpdate2', // Update an existing item with new value.
        'Key3': 'valueToUpdate3'    // Add a new key-value item.
    });
    // Channel metadata is updated.
} catch (e) {
    // Handle error.
}

Retrieve metadata

You can retrieve channel metadata by creating a List of keys to retrieve and passing it as an argument to a parameter in the getMetaData() method. A Map<String, String> collection is returned in the result with the corresponding key-value items.

try {
    final metaData = await channel.getMetaData(['key1', 'key2']);
} catch (e) {
    // Handle error.
}

Retrieve cached metadata

When Sendbird Chat SDK detects any of the create, read, update, and delete operations on the channel metadata, the SDK caches the metadata. The cached metadata is also updated whenever a channel list is fetched.

You can retrieve the cached metadata through the getCachedMetaData() method without having to query the server.

final metaData = channel.getCachedMetaData();

Delete metadata

You can delete channel metadata through the deleteMetaData() method as shown below.

try {
    await channel.deleteMetaData('key1');
    // Channel metadata is deleted.
} catch (e) {
    // Handle error.
}