fetch method

Future<T> fetch({
  1. required DocumentReference<Object?> ref,
  2. Source source = Source.serverAndCache,
})

Same as RepositoryAddon.transform but will return a Future with latest value in the DB using the given ref. If the given ref is not found, this will throw an exception.

Implementation

Future<T> fetch({
  required DocumentReference ref,
  Source source = Source.serverAndCache,
}) async {
  final snapshot = await ref
      .withConverter(
          fromFirestore: _repo.fromSnapshot, toFirestore: _repo.toMap)
      .get(GetOptions(source: source));
  final data = snapshot.data();
  if (data == null) {
    throw Exception("No document exists in the Ref: ${ref.path}");
  }
  return data;
}