update method

Future<void> update(
  1. Map<String, Object?> values
)

Writes each entry of values below this location, leaving other children alone. Keys may be multi-segment paths ('a/b'), which makes one atomic write to several places; a null value removes that child. Two keys where one path is the other or an ancestor of it ('a' and 'a/b', or 'a/b' and '/a//b') throw an ArgumentError; 'a' and 'ab' do not. A key that names this location itself ('', '/' or any string of only slashes) throws an ArgumentError that names the key, and nothing is written; use set to replace the location or remove to delete it.

An entry that is, or holds, a map with a non-null .priority and no value (only nulls or empty maps) throws an ArgumentError: the server answers such a merge with an error tied to no request, so its Future would never complete. set does not check this: there such a map is no data. A transaction at, above or below a written path may fail with overridden-by-set (see runTransaction).

An empty values map writes nothing and completes the Future in a microtask, with no write request.

The server refuses the whole update when keys create a node and set its priority separately ({'x/v': 1, 'x/.priority': 3} with x missing): the local write reverts and the Future fails with unknown and the server's reason. Write the node as one object instead, {'x': {'v': 1, '.priority': 3}}.

Implementation

Future<void> update(Map<String, Object?> values) {
  final Path path = spec.path;
  validateWritablePath('update', path);
  validateUserMerge('update', values, path);
  final Map<String, Object?> normalized =
      normalizeUserValue(values)! as Map<String, Object?>;
  final CompoundWrite write = CompoundWrite.fromValue(normalized);
  return database.write(
    (Repo repo, WriteCompletion done) =>
        repo.updateChildren(path, write, normalized, onComplete: done),
  );
}