覆盖 ChangeNotifier 中的 dispose 方法
Override dispose method in a ChangeNotifier
我有以下型号
class SelectorModel with ChangeNotifier {
.... // stuff relating to the model
}
在我的模型中,我使用以下方法获取 Firestore 文档流:
_subscription = Firestore.instance // _subscription is defined as an iVar above
.collection('myCollection')
.snapshots()
.listen((querySnapshot) {
_jobs = querySnapshot.documents;
callingMethod(''); // the method being called is inside of my model
});
我需要一种方法来处理 _subsciption
,这样当我的 Firestore 数据库发生变化时,它不会在我的模型已经被处理时尝试调用 callingMethod()
。
我正在寻找的是一种几乎与以下 ChangeNotifier 类似的方法:
@override
void dispose() {
super.dispose();
_subscription.cancel();
}
我查看了提供商 docs 但找不到任何东西。
感谢您的帮助!
如果我理解你,你可以这样做
_subscription = Firestore.instance // _subscription is defined as an iVar above
.collection('myCollection')
.snapshots()
.listen((querySnapshot) {
_jobs = querySnapshot.documents;
callingMethod(''); // the method being called is inside of my model
_subscription.cancel();
});
我有以下型号
class SelectorModel with ChangeNotifier {
.... // stuff relating to the model
}
在我的模型中,我使用以下方法获取 Firestore 文档流:
_subscription = Firestore.instance // _subscription is defined as an iVar above
.collection('myCollection')
.snapshots()
.listen((querySnapshot) {
_jobs = querySnapshot.documents;
callingMethod(''); // the method being called is inside of my model
});
我需要一种方法来处理 _subsciption
,这样当我的 Firestore 数据库发生变化时,它不会在我的模型已经被处理时尝试调用 callingMethod()
。
我正在寻找的是一种几乎与以下 ChangeNotifier 类似的方法:
@override
void dispose() {
super.dispose();
_subscription.cancel();
}
我查看了提供商 docs 但找不到任何东西。
感谢您的帮助!
如果我理解你,你可以这样做
_subscription = Firestore.instance // _subscription is defined as an iVar above
.collection('myCollection')
.snapshots()
.listen((querySnapshot) {
_jobs = querySnapshot.documents;
callingMethod(''); // the method being called is inside of my model
_subscription.cancel();
});