Flutter firebase firestore: 'path.isNotEmpty': a document path must be a non-empty string)
1,404
If looks like your id
variable is an empty string, which isn't a valid document ID to pass into doc()
.
Given how you initialize id
:
id = prefs.getString('id') ?? '';
It seems that prefs.getString('id')
returns null. You'll want to figure out what you want to do when that happens, but a simple way is to check with:
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(() {});
}
Author by
fizahpanda103
Updated on December 30, 2022Comments
-
fizahpanda103 over 1 year
im trying to make chat app for my flutter application. But this error is always come up everytime i try to click to chat. The error Can someone tell me what is wrong with my code.
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(() {});
}