toVCard method

List<String> toVCard()

Implementation

List<String> toVCard() {
  // BDAY (V3): https://tools.ietf.org/html/rfc2426#section-3.1.5
  // BDAY (V4): https://tools.ietf.org/html/rfc6350#section-6.2.5
  // ANNIVERSARY (V4): https://tools.ietf.org/html/rfc6350#section-6.2.6
  if ((FlutterContacts.config.vCardVersion == VCardVersion.v3 &&
          label == EventLabel.birthday) ||
      (FlutterContacts.config.vCardVersion == VCardVersion.v4 &&
          (label == EventLabel.birthday ||
              label == EventLabel.anniversary))) {
    final param = label == EventLabel.birthday ? 'BDAY' : 'ANNIVERSARY';
    if (FlutterContacts.config.vCardVersion == VCardVersion.v3) {
      return [
        '$param:'
            '${year == null ? '0000' : year.toString().padLeft(4, '0')}-'
            '${month.toString().padLeft(2, '0')}-'
            '${day.toString().padLeft(2, '0')}'
      ];
    } else {
      return [
        '$param:'
            '${year == null ? '--' : year.toString().padLeft(4, '0')}'
            '${month.toString().padLeft(2, '0')}'
            '${day.toString().padLeft(2, '0')}'
      ];
    }
  }
  return [];
}