createTemplateMap method

dynamic createTemplateMap()

Implementation

createTemplateMap() {
  List<CometChatMessageTemplate> localTypes =
      CometChatUIKit.getDataSource().getAllMessageTemplates(theme: theme);

  messageTypes?.forEach((element) {
    templateMap["${element.category}_${element.type}"] = element;
  });

  for (var element in localTypes) {
    String key = "${element.category}_${element.type}";

    CometChatMessageTemplate? localTemplate = templateMap[key];

    if (localTemplate == null) {
      templateMap[key] = element;
    } else {
      if (localTemplate.footerView == null) {
        templateMap[key]?.footerView = element.footerView;
      }

      if (localTemplate.headerView == null) {
        templateMap[key]?.headerView = element.headerView;
      }

      if (localTemplate.bottomView == null) {
        templateMap[key]?.bottomView = element.bottomView;
      }

      if (localTemplate.bubbleView == null) {
        templateMap[key]?.bubbleView = element.bubbleView;
      }

      if (localTemplate.contentView == null) {
        templateMap[key]?.contentView = element.contentView;
      }

      if (localTemplate.options == null) {
        templateMap[key]?.options = element.options;
      }
    }
  }
}