Flutter-PlatformException:错误,无效的文档参考.文档引用的段数必须为偶数,但用户的段数为1,则为null [英] Flutter - PlatformException : error, Invalid document reference. Document references must have an even number of segments, but users has 1, null

查看:179
本文介绍了Flutter-PlatformException:错误,无效的文档参考.文档引用的段数必须为偶数,但用户的段数为1,则为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Cloud Firestore获取用户数据.它首先起作用,但现在却引发了错误.

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

"PlatformException(PlatformException(错误,无效的文档引用.文档引用必须具有偶数个段,但用户具有1,空值))"

"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());
    }
  }

推荐答案

这几乎可以肯定是因为 uID 是一个空字符串.在传递给Firestore之前先进行检查.

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

这篇关于Flutter-PlatformException:错误,无效的文档参考.文档引用的段数必须为偶数,但用户的段数为1,则为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆