fromMap method Null safety

ContentBlockerTrigger fromMap(
  1. Map<String, dynamic> map
)

Implementation

static ContentBlockerTrigger fromMap(Map<String, dynamic> map) {
  var resourceType = <ContentBlockerTriggerResourceType?>[];
  var loadType = <ContentBlockerTriggerLoadType?>[];

  var resourceTypeStringList = List<String>.from(map["resource-type"] ?? []);
  resourceTypeStringList.forEach((type) {
    resourceType.add(ContentBlockerTriggerResourceType.fromValue(type));
  });

  var loadTypeStringList = List<String>.from(map["load-type"] ?? []);
  loadTypeStringList.forEach((type) {
    loadType.add(ContentBlockerTriggerLoadType.fromValue(type));
  });

  return ContentBlockerTrigger(
    urlFilter: map["url-filter"],
    urlFilterIsCaseSensitive: map["url-filter-is-case-sensitive"],
    ifDomain: List<String>.from(map["if-domain"] ?? []),
    unlessDomain: List<String>.from(map["unless-domain"] ?? []),
    resourceType: resourceType,
    loadType: loadType,
    ifTopUrl: List<String>.from(map["if-top-url"] ?? []),
    unlessTopUrl: List<String>.from(map["unless-top-url"] ?? []),
  );
}