linkMapFromJson function

LinkMap linkMapFromJson(
  1. Map<String, dynamic>? json
)

Parses json into a LinkMap The keys in json are expected to be the name of a ApptiveLinkType If the name does not match a know ApptiveLinkType the entry will be ignored

Implementation

LinkMap linkMapFromJson(Map<String, dynamic>? json) {
  if (json == null) {
    return {};
  }
  final linkTypeNames = ApptiveLinkType.values.map((type) => type.name);
  final knownTypes = json.keys.where((key) => linkTypeNames.contains(key));

  return Map.fromEntries(
    knownTypes.map(
      (type) => MapEntry(
        ApptiveLinkType.values.firstWhere((linkType) => linkType.name == type),
        ApptiveLink.fromJson(json[type]),
      ),
    ),
  );
}