【发布时间】:2020-06-07 01:29:20
【问题描述】:
好的。我已经使用 Flutter 一年多了。我几乎在每个应用程序中都使用了相同的代码,并且可以正常工作。出于某种原因,它在我正在构建的这个新应用程序中不起作用。
String testString(DocumentSnapshot doc, String val) {
try {
if (doc == null) {
return "error! DB not found!";
}
if (doc[val] == null) {
return "'" + val + "' doesn't exist in DB";
}
return doc[val];
} catch (e) {
return "Error: something went wrong";
}
}
我也试过这个:
String testUndString(DocumentSnapshot doc, String val) {
try {
return doc != null ? (doc[val] != null ? doc[val] : "undefined") : "undefined";
} catch (e) {
return "Error: something went wrong";
}
}
还有这个:
String testUndString(DocumentSnapshot doc, String val) {
try {
return doc.data != null ? (doc[val] != null ? doc[val] : "undefined") : "undefined";
} catch (e) {
return "Error: something went wrong";
}
}
经过一番搜索,看起来我已经正确完成了,但它仍然返回错误:
NoSuchMethodError (NoSuchMethodError: The method '[]' was called on null.)
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore