how to know if a new data added in to firebase collection.
my question is i need to push notification when the new data added to the firebase collection. here is my code look like. and i know it will work if i put this code in to the functin where i create the firebase collection. but in this case i want to code this here. how do i do that . here is the code i tried
StreamBuilder<List<StudentNotificationModel>>(
stream: _notificationImplementaion.readNotification(),
builder: (context, snapshot) {
final notification = snapshot.data;
if (snapshot.hasError) {
return const MessageWidget('Please Try Again');
}
if (snapshot.hasData) {
if (snapshot.data == null || snapshot.data!.isEmpty) {
return Text('empty')
}
// what should i check here?
if (newdata.added) {
log('New Data added');
pushNotificationCode();
}
return Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
shrinkWrap: true,
itemCount: notification.length,
itemBuilder: (context, index) {
final data = notification[index];
return HomeTile(
subtitle: data.notificationType,
title: data.title,
accountType: accountType,
);
},
),
);
}
return const Loading();
});
how do i do this
solution of this problem