getData method
Reads data from a Firestore document.
documentPath
: Path to the Firestore document.
Returns the document data as a Map<String, dynamic>
or null
if the document doesn't exist or an error occurs.
Implementation
Future<Map<String, dynamic>?> getData(String documentPath) async {
try {
final snapshot = await _firestore.doc(documentPath).get();
if (snapshot.exists) {
return snapshot.data() as Map<String, dynamic>?;
} else {
debugPrint('Document not found at path: $documentPath');
return null;
}
} catch (e) {
debugPrint('Error fetching document: $e');
return null;
}
}