CloudTask.fromSnapshot constructor

CloudTask.fromSnapshot(
  1. dynamic snapshot
)

Factory constructor to create a CloudTask from a Firestore snapshot.

Extracts the task details from the Firestore document snapshot, including the document ID, owner user ID, title, description, completion status, creation date, completion date/time (converted from Firestore timestamp), and eventual group id.

Implementation

CloudTask.fromSnapshot(QueryDocumentSnapshot<Map<String, dynamic>> snapshot)
  : documentId = snapshot.id,
    ownerUserId = snapshot.data()[ownerUserIdFieldName] as String,
    title = snapshot.data()[titleFieldName] as String,
    description =
        snapshot.data().containsKey(descriptionFieldName)
            ? snapshot.data()[descriptionFieldName] as String?
            : null,
    isCompleted = snapshot.data()[isCompletedFieldName] as bool,
    dueDate =
        snapshot.data().containsKey(dueDateFieldName) &&
                snapshot.data()[dueDateFieldName] != null
            ? (snapshot.data()[dueDateFieldName] as Timestamp).toDate()
            : null,
    creationDate =
        (snapshot.data()[creationDateFieldName] as Timestamp).toDate(),
    completionDateTime =
        snapshot.data().containsKey(taskCompletionDateTimeFieldName) &&
                snapshot.data()[taskCompletionDateTimeFieldName] != null
            ? (snapshot.data()[taskCompletionDateTimeFieldName] as Timestamp)
                .toDate()
            : null,
    groupId =
        snapshot.data().containsKey(groupIdFieldName)
            ? snapshot.data()[groupIdFieldName] as String?
            : null,
    assignedUserIds =
        snapshot.data().containsKey(assignedUserIdsFieldName) &&
                snapshot.data()[assignedUserIdsFieldName] != null
            ? List<String>.from(snapshot.data()[assignedUserIdsFieldName] as List)
            : const [];