首页 > 解决方案 > 如何修复“未处理的异常:错误状态:无法在 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,
          )

标签: firebaseflutter

解决方案


我发现了问题,profileId丢失了。


推荐阅读