Reputation: 475
im currently using a streambuilder to get my order data from firestore for a restaurant app and i want to make something when new order arrives, like a notification or something. How can i know if a new order added to database?
Upvotes: 1
Views: 837
Reputation: 48
You can subscribe to the stream you give in the "stream" field of your StreamBuilder
and use that subscription created to call the onData
property of StreamSubscription
. It will call the function present inside it whenever new data is added.
Example:
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){
});
Upvotes: 1