[英]Flutter Firesbase is returning Null
final db = FirebaseFirestore.instance.collection('dutyStatus');
Future<void> readOnDutyStatus() async {
//The function is being called in the authentication bloc
try {
List status = [];
// await db.add({'onDuty': true});
var data = await db.doc('driver1').get();
var temp = data.data();
status.add(temp);
print(
'_______________________________________________________________________________________');
print(status.toString());
print(
'_______________________________________________________________________________________');
} catch (e) {
print(e);
}
} }
The result : I/flutter (25466): _______________________________________________________________________________________结果:我/扑(25466):_______________________________________________________________________________________
I/flutter (25466): [null] I/颤振(25466):[空]
I/flutter (25466): _______________________________________________________________________________________我/颤振 (25466): ______________________________________________________________________________________
W/er_drive_mobil(25466): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed) W/er_drive_mobil(25466): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed) W/er_drive_mobil(25466): 访问隐藏方法 Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed) W/er_drive_mobil(25466): 访问隐藏方法 Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V(灰名单,链接,允许)
Note: The same code when used on another account of firebase works as intended and I can't seem to figure out the issue.注意:在另一个 firebase 帐户上使用的相同代码按预期工作,我似乎无法弄清楚问题所在。
Most likely driver1 doesn't exist.很可能 driver1 不存在。
Try this试试这个
var temp = data.exists ? data.data() : "Doc does not exist";
Print list should return [Doc does not exist]
instead of null.打印列表应返回
[Doc does not exist]
而不是 null。
Check if there is a white space before driver1 ie _driver1 or after it.检查 driver1 之前是否有空格,即 _driver1 或之后。 Otherwise there's no other explanation.
否则没有其他解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.