fromMap static method

ContactDate? fromMap(
  1. dynamic dyn
)

Implementation

static ContactDate? fromMap(final dyn) {
  if (dyn is Map<dynamic, dynamic>) {
    if (dyn[_kdate] == null && dyn[_kvalue] == null) {
      flutterContactLog.warning(
          "Received date with no value for either 'date' or 'value'");
      return null;
    }
    final label = dyn[_klabel] as String?;
    FlexiDate? flexi;
    try {
      flexi = (dyn[_kdate] != null || dyn[_kvalue] != null)
          ? FlexiDate.from(dyn[_kdate] ?? dyn[_kvalue])
          : null;
    } catch (e) {
      flutterContactLog.finer("Error parsing date: $dyn");
    }
    if (flexi?.isValid == true) {
      return ContactDate.ofDate(date: flexi!, label: label);
    } else if (flexi?.isValid == false && flexi?.source != null) {
      return ContactDate.ofValue(value: "$flexi", label: label);
    } else {
      return ContactDate.ofValue(value: dyn[_kvalue] as String, label: label);
    }
  }
  return null;
}