DiaryCard.fromMap constructor

DiaryCard.fromMap(
  1. String id,
  2. Map<String, dynamic> map
)

Creates a DiaryCard from a Firestore document map.

Parameters:

  • id: Document ID.
  • map: Map containing the fields.

Implementation

factory DiaryCard.fromMap(String id, Map<String, dynamic> map) {
final photoUrls = List<String>.from(map['photoUrls'] ?? []);
final imageUrl = photoUrls.isNotEmpty ? photoUrls.first : '';

return DiaryCard(
  id: id,
  title: map['title'] ?? '',
  date: DateTime.parse(map['date']),
  place: map['location'] ?? '',
  imageUrl: imageUrl,
);
}