我有 2 个 StreamSubscriptions,我想用它们从 Firebase 文档获取数据。
第一个是_trxnStream,第二个是_clientStream。
当我尝试使用这些 StreamSubscriptions 时,_trxnStream 工作正常。我可以从 trxns 文档中获取数据,但 _clientStream 无法从文档中提取数据。
late final StreamSubscription _trxnStream;
late final StreamSubscription _clientStream;
_trxnStream = _db
.collection('company')
.doc(ref.read(globalsNotifierProvider).companyId)
.collection('trxns')
.doc(ref.read(globalsNotifierProvider).currentTrxnId)
.snapshots()
.listen((trxnSnapshot) {
clientTypeController.text = trxnSnapshot.data()?['clientType'] ?? "";
_clientType = trxnSnapshot.data()?['clientType'] ?? "";
_clientId = trxnSnapshot.data()?['clientId'] ?? "";
_clientStream = _db
.collection('client')
.doc(_clientId)
.snapshots()
.listen((clientSnapshot) {
clientFNameController.text =
clientSnapshot.data()?['clientFName'] ?? ""; <<< THIS LINE IS NEVER EXECUTED
});
});
为什么我无法从客户端文档中获取数据? _clientId 具有正确的值来链接到正确的客户端文档。
感谢您的帮助
您确定 JSON 字段的命名正确吗?
它说
['clientFName']
也许这是一个拼写错误,而你的意思是 ['clientName']
如果这不是问题,它会抛出错误还是只给你一个空字符串?