firebase - Flutter-PlatformException:错误,无效的文档引用。文档引用的段数必须为偶数,但用户的段数为1,则为null

标签 firebase flutter dart google-cloud-firestore flutter-test

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

“PlatformException(PlatformException(错误,无效的文档引用。文档引用必须具有偶数个段,但是用户具有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之前先进行检查。

关于firebase - Flutter-PlatformException:错误,无效的文档引用。文档引用的段数必须为偶数,但用户的段数为1,则为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60696369/

相关文章:

http - 加载时间长,并且显示_InternalLinkedHashMap和列表<Dynamic>错误

flutter - 如何禁用 flutter web 的横向模式?

Flutter:如何映射 map 列表?

android - 在 Android Firebase 数据库中写入新数据

ios - Swift 从 firebase 存储中删除图像

javascript - 使用 if 语句确定 Firebase 用户是否可以访问某些 React Router 路径

dart - 如何从 Flutter 元素中读取数据

swift - Firebase 存储神秘消息 : libc++abi. dylib:以 NSException 类型的未捕获异常终止

firebase-realtime-database - 我需要做一个 firebase 流而不是一个 Http Get

redux - 使用ViewModel时导航到新屏幕并传递redux存储状态