getData method

Future<Map<String, dynamic>> getData(
  1. String collectionName,
  2. String docName
)

Retrieves data from a specified document within a collection.

The collectionName specifies the collection and docName specifies the document from which data is to be fetched. Returns a map of the data if the document exists.

Implementation

Future<Map<String, dynamic>> getData(
    String collectionName, String docName) async {
  DocumentSnapshot docSnapshot =
      await obj.collection(collectionName).doc(docName).get();
  if (docSnapshot.data() != null) {
    Map<String, dynamic> data = docSnapshot.data() as Map<String, dynamic>;
    print(data);
    return data;
  }
  return {};
}