无法无条件访问属性“uid”,因为接收者可以为“null”

时间:2021-04-19 08:14:56

标签: flutter google-cloud-firestore firebase-authentication flutter-layout flutter-dependencies

用户不工作。我没有在 Firebase 中上传集合

try {
  FirebaseAuth.instance.createUserWithEmailAndPassword
    (email: kEmail.text, password: kPassword.text)
      .then((value) {
    userCollection.doc(value.user.uid).set({
      'userName': kUserName,
      'email': kEmail,
      'password': kPassword,
      'uid': value.user.uid
    });
  });
} catch (err) {
  print(err.toString());
}

1

2 个答案:

答案 0 :(得分:1)

用户可以为空。所以先做空检查,比如

const context = canvas.getContext("2d")

context.beginPath()
context.arc(canvas.width/2, canvas.height/2, 30, 0, 2*Math.PI, false)
context.fillStyle = 'blue'
context.fill()

context.beginPath()
context.fillStyle = 'green' // I only moved this line up
context.fillRect(canvas.width/2, canvas.height/2, 100, 30)
context.fill()

或者一个简单的溶胶

try {
    FirebaseAuth.instance
        .createUserWithEmailAndPassword(
            email: kEmail.text, password: kPassword.text)
        .then((value) {
      if(value!=null && value.user != null){
         userCollection.doc(value.user.uid).set({
        'userName': kUserName,
        'email': kEmail,
        'password': kPassword,
        'uid': value.user.uid
         });
      }else{
        throw Error();
       }
      
    });
  } catch (err) {
    print(err.toString);
  }

答案 1 :(得分:-1)

改成这样

(e.data() 作为动态)['myFieldOne']

https://i.stack.imgur.com/IhA7h.png