fetchDocumentById method

Future<Map<String, dynamic>?> fetchDocumentById({
  1. required String docId,
})

Fetches a document from Firestore by its ID.

Implementation

Future<Map<String, dynamic>?> fetchDocumentById(
    {required String docId}) async {
  final now = DateTime.now();
  loggerService?.log("⌛ Fetching document with ID $docId in progress");

  try {
    final result =
        await firestoreReadService.fetchDocumentById(collection, docId);
    return result.data() as Map<String, dynamic>?;
  } catch (e) {
    final errorMessage = 'Error fetching document with ID $docId';
    loggerService?.logError(errorMessage, e.toString());
    rethrow;
  } finally {
    loggerService?.logCompletionTime(now, 'Fetching document');
  }
}