【发布时间】:2022-11-04 04:12:43
【问题描述】:
如何知道是否有新数据添加到 Firebase 集合中。
我的问题是当新数据添加到 firebase 集合时我需要推送通知。 这是我的代码样子。 我知道如果我把这段代码放到我创建firebase集合的函数中它会起作用。 但在这种情况下,我想在这里编写代码。 我怎么做 。这是我尝试过的代码
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();
});
我该怎么做呢
这个问题的解决方案
【问题讨论】:
-
云功能触发器是解决方案。 StreamBuilder 仅用于根据获取的数据呈现 UI。不是为了触发函数
标签: flutter dart flutter-notification