Firebase 基于新数据的颤振Streambuilder
我目前正在使用streambuilder从firestore获取餐厅应用程序的订单数据,我想在新订单到达时制作一些东西,比如通知之类的东西。如何知道数据库中是否添加了新订单?您可以订阅您在Firebase 基于新数据的颤振Streambuilder,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我目前正在使用streambuilder从firestore获取餐厅应用程序的订单数据,我想在新订单到达时制作一些东西,比如通知之类的东西。如何知道数据库中是否添加了新订单?您可以订阅您在StreamBuilder的“stream”字段中提供的流,并使用创建的订阅调用StreamSubscription的onData属性。每当添加新数据时,它将调用其中的函数 例如: Stream stream = <YOUR STREAM HERE>; StreamSubscription stre
StreamBuilder
的“stream”字段中提供的流,并使用创建的订阅调用StreamSubscription
的onData
属性。每当添加新数据时,它将调用其中的函数
例如:
Stream stream = <YOUR STREAM HERE>;
StreamSubscription streamSub;
String actionTaken(dynamic data){
return data;
}
//call the code below in initState if you want to start it with the app.
streamSub = stream.listen(actionTaken);
subscription.onData((data){
});
Stream=;
streamSub;
采取的字符串操作(动态数据){
返回数据;
}
//如果要使用应用程序启动,请在initState中调用下面的代码。
streamSub=stream.listen(已采取的操作);
订阅.onData((数据){
});
只需在Firestore.instance.collection(collection\u NAME).snapshots()上使用StreamBuilder即可。下一次请提供您的代码并研究您提出的问题。您可能可以打印onData调用中的数据。