【发布时间】:2020-09-08 05:19:52
【问题描述】:
我的 Web 应用程序要求我为文档 jkl 使用 firestore 侦听器。它不是打印一次更新的值,而是重复打印该值,即使文档 jkl 中没有更新。
void switchListener() async
{
_listener = Firestore.instance
.collection('abc')
.document('def')
.collection('ghi')
.document('jkl')
.snapshots()
.listen((data) => listenerUpdate(data));
}
void listenerUpdate(data)
{
String number = data['URL'];
setState(() {
_totalDocs = number;
});
}
我能得到一些帮助吗?
更新
监听器只有在点击按钮后才会被激活。
onPressed: () {
switchListener();
},
void switchListener() async {
_listener = Firestore.instance
.collection('abc')
.document('def')
.collection('jkl')
.document('mno')
.snapshots()
.distinct()
.listen((data) => listenerUpdate(data));
_listener.cancel();
}
void listenerUpdate(data) {
String number = data['physicianNote'];
String url = data['signedURL'];
setState(() {
_totalDocs = number;
_signedurl = url;
});
print("totalDoc: "+_totalDocs);
print("url: "+_signedurl);
js.context.callMethod("open", [signedurl]);
}
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore