writeData method

Future<bool> writeData(
  1. String documentPath,
  2. Map<String, dynamic> data, {
  3. bool merge = false,
})

Writes data to a Firestore document via set

  • documentPath: Path to the Firestore document.
  • data: The data to write.
  • merge: Whether to merge data with existing content (default: true).

Returns true if the operation is successful, false otherwise.

Implementation

Future<bool> writeData(String documentPath, Map<String, dynamic> data, {bool merge = false}) async {
  try {
    await _firestore.doc(documentPath).set(data, SetOptions(merge: merge));
    debugPrint('Document created or merged successfully.');
    return true;
  } catch (e) {
    debugPrint('Error writing data to Firestore with set: $e');
    return false;
  }
}