Flutter:类“ DatabaseReference”没有实例方法“ cancel”

时间:2020-06-26 15:18:46

标签: firebase flutter dart firebase-realtime-database

我在取消Firebase监听器时遇到异常

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown while finalizing the widget tree:
Class 'DatabaseReference' has no instance method 'cancel'.
Receiver: Instance of 'DatabaseReference'
Tried calling: cancel()

这是我的代码

var databaseRef;

databaseRef = FirebaseDatabase.instance.reference().child("messages");

  @override
  void dispose() {
    _sendMessageTextController.dispose();
    databaseRef?.cancel();

    super.dispose();
  }

任何人都知道我为什么要超越execptioin

如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。

1 个答案:

答案 0 :(得分:0)

API documentation for DocumentReference中可以看到,该对象上没有称为cancel的方法。