toMap method

Map<String, dynamic> toMap()

Implementation

Map<String, dynamic> toMap() {
  List<String> resourceTypeStringList = [];
  resourceType.forEach((type) {
    resourceTypeStringList.add(type.toNativeValue());
  });
  List<String> loadTypeStringList = [];
  loadType.forEach((type) {
    loadTypeStringList.add(type.toNativeValue());
  });
  List<String> loadContextStringList = [];
  loadContext.forEach((type) {
    loadContextStringList.add(type.toNativeValue());
  });

  Map<String, dynamic> map = {
    "url-filter": urlFilter,
    "if-frame-url": ifFrameUrl,
    "url-filter-is-case-sensitive": urlFilterIsCaseSensitive,
    "if-domain": ifDomain,
    "unless-domain": unlessDomain,
    "resource-type": resourceTypeStringList,
    "load-type": loadTypeStringList,
    "if-top-url": ifTopUrl,
    "unless-top-url": unlessTopUrl,
    "load-context": loadContextStringList
  };

  map.keys
      .where((key) =>
          map[key] == null ||
          (map[key] is List && (map[key] as List).length == 0)) // filter keys
      .toList() // create a copy to avoid concurrent modifications
      .forEach(map.remove);

  return map;
}