setTags method

Future<void> setTags({
  1. required Map<String, String> tags,
})

Set multiple tags with a Map, the keys of the map are the tags, the values the values for the corresponding tag. Tags are converted to MBAudienceTag classes and saved with _saveNewTags. @param tags The map of tags and values.

Implementation

Future<void> setTags({required Map<String, String> tags}) async {
  List<MBAudienceTag> newTags = (await _getTags()) ?? [];
  for (String key in tags.keys) {
    String? value = tags[key];
    if (value != null) {
      int index = newTags.indexWhere((t) => t.tag == key);
      if (index != -1) {
        MBAudienceTag tag = newTags[index];
        tag.value = value;
        newTags[index] = tag;
      } else {
        newTags.add(MBAudienceTag(key, value));
      }
    }
  }
  await _saveNewTags(newTags);
  await MBAudienceManager.shared.updateMetadata();
}