/ 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 channel metacounters

Copy link

Using a channel metacounter, you can store additional information to channels such as the number of likes on a message. A channel metacounter in Map<String, int> can be stored into a Channel object and can be fetched or rendered into the UI.

A channel metacounter is primarily used to track and update discrete indicators in a channel. Use channel metacounters instead of channel metadata when you need an integer with increasing and decreasing atomic operations.


Create a metacounter

Copy link

To store channel metacounter into a channel, create Map<String *, int> and add key-value items. Then pass the map as an argument to a parameter when calling the createMetaCounters() method. You can put multiple key-value items in the map.

try {
    final metaCounters = await channel.createMetaCounters({'key1': 1, 'key2': 2});
    // Channel metacounters are created.
} catch (e) {
    // Handle error.
}

Update a metacounter

Copy link

The procedure of updating a channel metacounter is the same as creating a channel metacounter. Through the updateMetaCounters() method, values of existing keys are updated and values of new keys are added.

try {
    final metaCounters = await channel.updateMetaCounters({'key1': 3, 'key2': 4});
    // Channel metacounters are updated.
} catch (e) {
    // Handle error.
}

Increase values in a metacounter

Copy link

You can increase values in a channel metacounter by passing a Map<String, int> of keys to increase as an argument to a parameter in the increaseMetaCounters() method. The values of corresponding keys in the metacounter are increased by the specified number.

try {
    final metaCounters = await channel.increaseMetaCounters({'key1': 5, 'key2': 2});
    // If the value of key1 was 3, it's 8 now.
} catch (e) {
    // Handle error.
}

Decrease values in a metacounter

Copy link

You can decrease values in a channel metacounter by passing a Map<String, int> of keys to decrease as an argument to a parameter in the decreaseMetaCounters() method. The values of corresponding keys in the metacounter are decreased by the specified number.

try {
    final metaCounters = await channel.decreaseMetaCounters({'key1': 5, 'key2': 2});
    // if the value of key1 was 8, it's 3 now.
} catch (e) {
    // Handle error.
}

Retrieve a metacounter

Copy link

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

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

Delete a metacounter

Copy link

You can delete a channel metacounter as shown below.

try {
    await channel.deleteMetaCounters('key1');
} catch (e) {
    // Handle error.
}