Flutter - PlatformException : error, Invalid document reference. Document references must have an even number of segments, but users has 1, null

☆樱花仙子☆ 提交于 2021-01-29 08:06:46

问题


I wanted to get my users data from cloud firestore. It worked first but now it is raising a error.

"PlatformException (PlatformException(error, Invalid document reference. Document references must have an even number of segments, but users has 1, null))"

String name = "", email = "", pnumber = "", imgUrl = "", bio = "", posted = "", applied = "", rating = "", saved = "";
String url;
final formKey = new GlobalKey<FormState>();
final databaseReference = Firestore.instance;

String uID;

  @override

  void initState() {

    super.initState();
    uID = widget.uID;
    print("UID  " + uID);
    getUser();
  }

void getUser() {
    try {
      databaseReference
          .collection('users')
          .document(uID)
          .get()
          .then((DocumentSnapshot ds){
        if (ds.exists) {
          name = ds.data['fullname'].toString();
          print(name);
          email = ds.data['email'].toString();
          print(email);
          pnumber = ds.data['pnumber'].toString();
          print(pnumber);
          imgUrl = ds.data['imgUrl'].toString();
          print(imgUrl);
          bio = ds.data['bio'].toString();
          print(bio);
          posted = ds.data['posted'].toString();
          print(posted);
          applied = ds.data['applied'].toString();
          print(applied);
          rating = ds.data['rating'].toString();
          print(rating);
          saved = ds.data['saved'].toString();
          print(saved);
          print(ds.data['fullname'].toString());

        } else {
          print("No such user");
        }
      });
    } catch (e) {
      print(e.toString());
    }
  }

回答1:


This is almost certainly because uID is an empty string. Check it before passing to Firestore.



来源:https://stackoverflow.com/questions/60696369/flutter-platformexception-error-invalid-document-reference-document-refere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!