简体   繁体   English

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

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

I have a firestore database. 我有一个Firestore数据库。 What I want to know is how to check if a certain Document reference exists in this database. 我想知道的是如何检查此数据库中是否存在某个文档引用。 The code I have used to work but now it's broken. 我曾经工作过的代码,但是现在坏了。

Get reference 获取参考

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

check if data exists 检查数据是否存在

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

By the way I know for a fact that this Reference does not exists. 顺便说一下,我知道这个参考文献不存在。 I just want to make sure that if it does i can update the travel variable. 我只想确保如果可以,我可以更新旅行变量。

The error I get 我得到的错误

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)

If you call an object that doesn't exist, how can you expect your travelTotalReference to be anything but null. 如果调用不存在的对象,那么如何期望travelTotalReference为null。

Since then calling get() on it return an error, seems fair... 从那以后调用get()返回错误,看起来很公平。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoSuchMethodError:在 Flutter 中使用 Dart 和 Firestore 在 null 上调用了方法“get” - NoSuchMethodError: The method 'get' was called on null in Flutter using Dart with Firestore Flutter Firestore - NoSuchMethodError:在 null 上调用了方法“[]” - Flutter Firestore - NoSuchMethodError: The method '[]' was called on null Flutter - NoSuchMethodError: 方法 '[]' 在 null 上被调用 - Flutter - NoSuchMethodError: The method '[]' was called on null NoSuchMethodError: 在 null 上调用了方法“[]”。 (扑) - NoSuchMethodError: The method '[]' was called on null. (Flutter) 颤振未处理的异常:NoSuchMethodError:方法'then'在null上被调用 - Flutter Unhandled Exception: NoSuchMethodError: The method 'then' was called on null Flutter NoSuchMethodError:在 null 上调用了方法“toDate” - Flutter NoSuchMethodError: The method 'toDate' was called on null Flutter“NoSuchMethodError(NoSuchMethodError:在 null 上调用了方法‘where’。 - Flutter "NoSuchMethodError (NoSuchMethodError: The method 'where' was called on null." Error Flutter - Mockito Firestore...get() - 在 null 上调用了方法“document” - Flutter - Mockito Firestore...get() - The method 'document' was called on null 未处理的异常:NoSuchMethodError:在 null 上调用了方法“[]”。 访问firestore时 - Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. when accessing firestore NoSuchMethodError:在 null 上调用了方法“验证”……flutter-Firebase - NoSuchMethodError: The method 'validate' was called on null ...... flutter-Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM