pushChild function

String pushChild(
  1. String path
)

A new child key under path, generated locally.

No request is made: the key is derived from the clock and a random seed, so it can be written to immediately with setValue.

Implementation

String pushChild(String path) {
  const cap = 64;
  final p = path.toNativeUtf8();
  final out = calloc<Uint8>(cap);
  try {
    final rc = fdbDbPush(p.cast(), out.cast(), cap);
    if (rc < 0) {
      throw switch (rc) {
        -1 => StateError('pushChild before the Firebase app was initialized'),
        -2 => ArgumentError('a path is required'),
        _ => StateError('pushChild failed ($rc)'),
      };
    }
    return utf8.decode(out.asTypedList(rc));
  } finally {
    calloc
      ..free(p)
      ..free(out);
  }
}