当我再次尝试登录时,出现此错误:- getter 'uid' 被调用为 null

时间:2021-06-13 04:12:32

标签: flutter dart

当我安装并启动应用程序并登录时,我不会收到错误消息,但是如果我曾经注销过,则会收到此错误消息。现在,如果用户已注销,为什么它甚至说在 null 上调用了 getter uid。

错误将我带到这一行,它位于主屏幕(用户登录时的第一个屏幕)内。帮我解决这个问题:-

 matchReference = db.collection("users")
        .doc(auth.currentUser.uid).collection('Matches');
  

1 个答案:

答案 0 :(得分:0)

当 currentUser 为空时调用 uid 会导致错误。 您应该先检查用户是否存在,然后再调用 uid

    if(auth.currentUser != null){
        matchReference = db.collection("users").doc(auth.currentUser.uid).collection('Matches');
      }