【问题标题】:ERROR: The method 'then' can't be unconditionally invoked because the receiver can be 'null错误:无法无条件调用方法“then”,因为接收者可以为“null”
【发布时间】:2022-01-07 18:09:31
【问题描述】:

方法'then'不能被无条件调用,因为receiver可以是'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");

                                              });
             })

【问题讨论】:

    标签: android firebase flutter dart


    【解决方案1】:

    像这样为 currentUser 属性添加一个空检查

    auth.currentUser!.then((value){
    
    // your code here
    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-10
      • 2023-03-05
      • 1970-01-01
      • 2021-09-05
      • 2021-10-05
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2021-08-27
      相关资源
      最近更新 更多