createData method

Future<bool> createData({
  1. required String collection,
  2. required Map<String, dynamic> data,
  3. String? id,
  4. bool isErrorDialog = true,
  5. dynamic onError(
    1. String? message
    )?,
})

Implementation

Future<bool> createData({
  required String collection,
  required Map<String, dynamic> data,
  String? id,
  bool isErrorDialog = true,
  Function(String? message)? onError,
}) async {
  // try {
  if (id == null) {
    return await _firestore
        .collection(collection)
        .add(data)
        .then((value) => true)
        .catchError((error) async {
      if (isErrorDialog) {
        GetxFire.openDialog.messageError(error.toString());
      } else {
        await GetxFire.hideProgressHud();
      }
      if (onError != null) onError(error);
      return false;
    });
  } else {
    return await _firestore
        .collection(collection)
        .doc(id)
        .set(data)
        .then((value) => true)
        .catchError((error) async {
      if (isErrorDialog) {
        GetxFire.openDialog.messageError(error.toString());
      } else {
        await GetxFire.hideProgressHud();
      }
      if (onError != null) onError(error);
      return false;
    });
  }
  // } catch (e) {
  //   GetxFire.openDialog.messageError(e.toString());
  //   return false;
  // }
}