簡體   English   中英

Flutter Firestore NoSuchMethodError:方法“ get”在null上被調用

[英]Flutter Firestore NoSuchMethodError: The method 'get' was called on null

我有一個Firestore數據庫。 我想知道的是如何檢查此數據庫中是否存在某個文檔引用。 我曾經工作過的代碼,但是現在壞了。

獲取參考

travelTotalReference =
        Firestore.instance.document('$_id/$_presentDate BalanceTotal');

檢查數據是否存在

 travelTotalReference.get().then((dataSnapshot) {
        if (dataSnapshot.exists) {
          setState(() {
            travel = dataSnapshot.data['total'];
          });
        }else{
          setState(() {
            travel = 0;
          });
        }
      });

順便說一下,我知道這個參考文獻不存在。 我只想確保如果可以,我可以更新旅行變量。

我得到的錯誤

E/flutter (17184): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: 
Unhandled exception:
E/flutter (17184): NoSuchMethodError: The method 'get' was called on null.
E/flutter (17184): Receiver: null
E/flutter (17184): Tried calling: get()
E/flutter (17184): #0      Object.noSuchMethod 
(dart:core/runtime/libobject_patch.dart:48:5)

如果調用不存在的對象,那么如何期望travelTotalReference為null。

從那以后調用get()返回錯誤,看起來很公平。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM