add method

Future<DocumentReference<Object?>> add({
  1. required T item,
  2. SetOptions? setOptions,
  3. required String type,
  4. DocumentReference<Object?>? parent,
})

Given item will be added to the collection with name type, which is inside the document parent. If parent is null, global collection with name type will be used to store the item.

Will return the DocumentReference that was used to store item.

Implementation

Future<DocumentReference> add({
  required T item,
  SetOptions? setOptions,
  required String type,
  DocumentReference? parent,
}) async {
  final data = toMap(item, setOptions);
  final ref = _merge(type, parent).doc(item.id);
  if (await _checkConnectivity()) {
    await ref.set(data);
  } else {
    ref.set(data);
  }
  return ref;
}