Home > other >  flutter firebase delete operation
flutter firebase delete operation

Time:12-29

my file deletion on firebase is failing. Is there anyone who can help? On this code: _currentUserVergiID!.vergiID as Vergi, I get:

_CastError (Null check operator used on a null value)"

The codes are as follows:

  @override
  Future deleteVergi(String currentUserID, Vergi docID) async {
    //var _vergiID = _firebaseFirestoreDB.collection("hizmetler").doc().id;
    var vergi = await _firebaseFirestoreDB
        .collection("hizmetler")
        .doc(currentUserID)
        .collection("vergi")
        .doc(docID.vergiID)
        .delete();
    return vergi;

ListView delete metod

onDismissed: (direction) async {
                          await _userModel.deleteVergi(
                            _currentUser.userID,
                            _currentUserVergiID!.vergiID as Vergi
                          );
                        },

CodePudding user response:

I would change the parameters in the userModel.deleteVergi to a string documents the same you done with currentUserID document Id tends do be String Within Firebase and make my code as follow:

'''

    @override
  Future deleteVergi(String currentUserID, String docID) async {

   await _firebaseFirestoreDB
        .collection("hizmetler")
        .doc(currentUserID)
        .collection("vergi")
        .doc(docID)
        .delete();

'''

I do not see why I would return something since you are just deleting something.

and Here would be like This: '''

onDismissed: (direction) async {
                          await _userModel.deleteVergi(
                            _currentUser.userID,
                             //Remember this is doc ID now is a String.
                            _currentUserVergiID!.vergiID 
                          );
                        },

'''

CodePudding user response:

menote I am getting it from document snapshot

    class Vergi {
  final String? kim;
  final String? aciklama;
  final double fiyat;
  final DateTime? aciklamaDate;
  final String? vergiID;

Vergi.fromMap(DocumentSnapshot snapshot)
      : aciklama = snapshot["aciklama"],
        fiyat = snapshot["fiyat"],
        aciklamaDate = snapshot["aciklamaDate"],
        kim = snapshot["kim"],
        vergiID = snapshot.id;

  • Related