Ffltter Firebase Firestore:'path.isNotEmpty':文档路径必须为非空字符串) [英] Flutter firebase firestore: 'path.isNotEmpty': a document path must be a non-empty string)

查看:38
本文介绍了Ffltter Firebase Firestore:'path.isNotEmpty':文档路径必须为非空字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的扑翼应用程序制作聊天应用程序。但是每次我尝试点击聊天时都会出现这个错误。The error 有人能告诉我我的代码出了什么问题吗?

readLocal() async {
prefs = await SharedPreferences.getInstance();
id = prefs.getString('id') ?? '';
if (id.hashCode <= peerId.hashCode) {
  groupChatId = '$id-$peerId';
} else {
  groupChatId = '$peerId-$id';
}
FirebaseFirestore.instance
    .collection('users')
    .doc(id)
    .update({'chattingWith': peerId});

setState(() {});

}

推荐答案

If看起来id变量是空字符串,这不是要传递给doc()的有效文档ID。

给定您初始化id的方式:

id = prefs.getString('id') ?? '';

似乎prefs.getString('id')返回NULL。您需要弄清楚发生这种情况时要做什么,但简单的方法是检查:

id = prefs.getString('id');
if (!id.isEmpty) {
  if (id.hashCode <= peerId.hashCode) {
    groupChatId = '$id-$peerId';
  } else {
    groupChatId = '$peerId-$id';
  }
  FirebaseFirestore.instance
    .collection('users')
    .doc(id)
    .update({'chattingWith': peerId});

  setState(() {});
}

这篇关于Ffltter Firebase Firestore:&#39;path.isNotEmpty&#39;:文档路径必须为非空字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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