Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Flatter中从firebase数据库检索数据?_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

如何在Flatter中从firebase数据库检索数据?

如何在Flatter中从firebase数据库检索数据?,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我试图从firestore检索数据并将val放入if语句中,但当我这样做时,它给了我以下错误: I/flutter ( 8492): Closure: () => String from Function 'toString':. 这是我的密码: void getUserData() async { try { firestoreInstance .collection('Users') .document(usernameCo

我试图从firestore检索数据并将val放入if语句中,但当我这样做时,它给了我以下错误:

I/flutter ( 8492): Closure: () => String from Function 'toString':.
这是我的密码:

void getUserData() async {
    try {
      firestoreInstance
          .collection('Users')
          .document(usernameController.text)
          .get()
          .then((value) {
        setState(() {
          email = (value.data)['email'];
          password = (value.data)['password'];
          gender = (value.data)['gender'];
          username = (value.data)['username'];
          userType = (value.data)['userType'];
        });
      });
    } catch (e) {
      print(e.toString);
    }
  }
忘了提到,当我打印userType时,它是一个文本,它会给我NULL

只需删除您的()

}

或者像这样使用

void getUserData() async {
try {
  firestoreInstance
      .collection('Users')
      .document(usernameController.text)
      .get()
      .then((value) {
    setState(() {
      email = value.data['email'];
      password = value.data['password'];
      gender = value.data['gender'];
      username = value.data['username'];
      userType = value.data['userType'];
    });
  });
} catch (e) {
  print(e.toString);
}
username = value['username'];