简体   繁体   中英

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

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");

                                              });
             })
auth.currentUser?.then((value) {

Add a null check to the currentUser property like this

auth.currentUser!.then((value){

// your code here

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM