updateData method

Future<DocumentSnapshot> updateData(
  1. Map<String, dynamic> data
)

Updates fields in the document referred to by this DocumentReference.

If no document exists yet, the update will fail.

Implementation

Future<DocumentSnapshot> updateData(Map<String, dynamic> data) async {
  // if we don't have the document ID, get it first.
  if (id == null) _id = (await get())?.id;

  // early out if this document does not exist
  if (_id == null) {
    throw CarpServiceException('No valid document id found.');
  }

  Map<String, dynamic> payload = {'name': name, 'data': data};

  final response = await service._put(
    documentUri,
    body: json.encode(payload),
  );

  Map<String, dynamic> responseJson =
      service._handleResponse(response) as Map<String, dynamic>;
  return DocumentSnapshot._(path, responseJson);
}