CloudTask.fromDocument constructor
- dynamic doc
Factory constructor to create a CloudTask from a Firestore document snapshot.
This is used when retrieving a single document from Firestore.
Implementation
factory CloudTask.fromDocument(DocumentSnapshot<Map<String, dynamic>> doc) {
final data = doc.data();
if (data == null) {
throw Exception("Document \\${doc.id} does not exist.");
}
return CloudTask(
documentId: doc.id,
ownerUserId: data[ownerUserIdFieldName] as String,
title: data[titleFieldName] as String,
description:
data.containsKey(descriptionFieldName)
? data[descriptionFieldName] as String?
: null,
isCompleted: data[isCompletedFieldName] as bool,
dueDate:
data.containsKey(dueDateFieldName) && data[dueDateFieldName] != null
? (data[dueDateFieldName] as Timestamp).toDate()
: null,
creationDate: (data[creationDateFieldName] as Timestamp).toDate(),
completionDateTime:
data.containsKey(taskCompletionDateTimeFieldName) &&
data[taskCompletionDateTimeFieldName] != null
? (data[taskCompletionDateTimeFieldName] as Timestamp).toDate()
: null,
groupId:
data.containsKey(groupIdFieldName)
? data[groupIdFieldName] as String?
: null,
assignedUserIds:
data.containsKey(assignedUserIdsFieldName) && data[assignedUserIdsFieldName] != null
? List<String>.from(data[assignedUserIdsFieldName] as List)
: const [],
);
}