fromMap static method

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

Implementation

static WebHistory? fromMap(Map<String, dynamic>? map) {
  if (map == null) {
    return null;
  }

  List<LinkedHashMap<dynamic, dynamic>>? historyListMap =
      map["history"]?.cast<LinkedHashMap<dynamic, dynamic>>();
  int currentIndex = map["currentIndex"];

  List<WebHistoryItem> historyList = <WebHistoryItem>[];
  if (historyListMap != null) {
    for (var i = 0; i < historyListMap.length; i++) {
      var historyItem = historyListMap[i];
      historyList.add(WebHistoryItem(
          originalUrl: historyItem["originalUrl"] != null
              ? Uri.tryParse(historyItem["originalUrl"])
              : null,
          title: historyItem["title"],
          url: historyItem["url"] != null
              ? Uri.tryParse(historyItem["url"])
              : null,
          index: i,
          offset: i - currentIndex));
    }
  }

  return WebHistory(list: historyList, currentIndex: currentIndex);
}