fromMap static method

SectionEntity? fromMap(
  1. Object? o, {
  2. Map<String, String>? newDocumentIds,
})

Implementation

static SectionEntity? fromMap(Object? o,
    {Map<String, String>? newDocumentIds}) {
  if (o == null) return null;
  var map = o as Map<String, dynamic>;

  var imageIdNewDocmentId = map['imageId'];
  if ((newDocumentIds != null) && (imageIdNewDocmentId != null)) {
    var imageIdOldDocmentId = imageIdNewDocmentId;
    imageIdNewDocmentId = newRandomKey();
    newDocumentIds[imageIdOldDocmentId] = imageIdNewDocmentId;
  }
  var linksFromMap = map['links'];
  List<LinkEntity> linksList;
  if (linksFromMap != null) {
    linksList = (map['links'] as List<dynamic>)
        .map((dynamic item) =>
            LinkEntity.fromMap(item as Map, newDocumentIds: newDocumentIds)!)
        .toList();
  } else {
    linksList = [];
  }

  return SectionEntity(
    title: map['title'],
    description: map['description'],
    imageId: imageIdNewDocmentId,
    imagePositionRelative: map['imagePositionRelative'],
    imageAlignment: map['imageAlignment'],
    imageWidth: double.tryParse(map['imageWidth'].toString()),
    links: linksList,
  );
}