Home > Enterprise >  ERROR: The method 'then' can't be unconditionally invoked because the receiver can be
ERROR: The method 'then' can't be unconditionally invoked because the receiver can be

Time:01-08

The method 'then' can't be unconditionally invoked because the receiver can be 'null

IconButton(icon: Icon(Icons.favorite_border), onPressed: (){
               FirebaseAuth auth = FirebaseAuth.instance;
               auth.currentUser.then((value) {
                 DatabaseReference favRef = FirebaseDatabase().reference().child("Posts").child(uploadId).child("Fav").child(value.uid).child("state");
                 favRef.set("true");

                                              });
             })

CodePudding user response:

auth.currentUser?.then((value) {

CodePudding user response:

Add a null check to the currentUser property like this

auth.currentUser!.then((value){

// your code here

}
  •  Tags:  
  • Related