documentToJson method

JsonObject documentToJson(
  1. Document document
)

Implementation

JsonObject documentToJson(Document document) {
  final docJson = <String, dynamic>{};

  final entries = document.fields?.entries ?? [];

  for (final entry in entries) {
    docJson[entry.key] = valueUtils.toJsonObject(entry.value);
  }

  docJson[metaName] = document.id;

  if (document.createTime != null) {
    final createTime =
        DateTime.tryParse(document.createTime!)?.toUtc().toIso8601String();
    docJson[metaCreateTime] = createTime;
  }

  if (document.updateTime != null) {
    final updateTime =
        DateTime.tryParse(document.updateTime!)?.toUtc().toIso8601String();
    docJson[metaUpdateTime] = updateTime;
  }

  return docJson;
}