createUniqueDocument method

Future<String?> createUniqueDocument(
  1. String collectionPath,
  2. Map<String, dynamic> data
)

Creates a new document in a Firestore collection with a unique ID.

  • collectionPath: Path to the Firestore collection.
  • data: The data to write to the new document.

Returns the unique document ID on success, or null if an error occurs.

Implementation

Future<String?> createUniqueDocument(String collectionPath, Map<String, dynamic> data) async {
  try {
    final docRef = await _firestore.collection(collectionPath).add(data);
    debugPrint('Document created with ID: ${docRef.id}');
    return docRef.id;
  } catch (e) {
    debugPrint('Error creating document: $e');
    return null;
  }
}