firebase - 如何修复“未处理的异常:错误状态:无法在 DocumentSnapshotPlatform 上获取不存在的字段”?
问题描述
我有一个函数可以在导航到另一个页面之前从 firebase 获取一个值。不幸的是,当调用该函数时,我收到此错误“未处理的异常:错误状态:无法获取 DocumentSnapshotPlatform 上不存在的字段”。但是,如果我热重载我的应用程序,则会调用该函数并且该值就在那里。你们知道我该如何解决这个问题吗?
这是功能:
Future<void> getDeliveryPrice(String profileId) async {
final DocumentSnapshot doc = await storeRef.doc(profileId).get();
final price = doc['delPrice'] as num;
deliveryPrice = price;
print(profileId);
notifyListeners();
}
这里是我调用函数的地方:
PriceCard(
buttonText: 'Continuar para a Entrega',
onPressed: cartManager.isCartValid
? () {
cartManager.getDeliveryPrice(profileId);
print(profileId);
Navigator.push(
context, MaterialPageRoute(
builder: (context) => AddressScreen(profileId),
));
} : null,
)
解决方案
我发现了问题,profileId
丢失了。
推荐阅读
- .net - 我们如何在单声道中使用 dot net dll?
- javascript - 如何在 ionic 应用程序中从 HTML 生成 PDF
- r - 按行子集数据帧时出错
- c# - iText7 在运行时动态设置字段计算
- sql-server - 如何从 Nodejs 执行存储过程
- javascript - javascript 正在读取即将到来的空日期为 1/1/1970
- sql - 如何添加引用 2 个唯一列和表中 1 个唯一列的主 ID(多个连接)
- java - XPath 返回错误的元素
- python - Twitter API 向我发送“不完整”状态
- java - RabbitMQ 健康检查失败