【发布时间】:2020-11-08 01:48:26
【问题描述】:
在我的系统中有状态为“已批准”和“未批准”的通知。我只想显示“未批准”的通知,并且我想通过使用颤振应用程序将它们转换为“已批准”。 这是我的火力基地的截图。
通过使用以下代码,我可以显示通知所有通知列表
Widget build(BuildContext context) {
final notices = Provider.of<List<Notice>>(context) ?? [];
return StreamBuilder<List<Notice>>(
stream: NoticeService().notices,
builder: (context, snapshot) {
if(snapshot.hasData){
return GridView.builder (
itemCount: notices.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 1),
// ignore: missing_return
itemBuilder: (context,index){
return SingleNotice(
notice:notices[index]
);
}
);
}else{
return(Text('No List'));
}
}
);
}
我像这样创建通知流
final CollectionReference noticeCollection=Firestore.instance.collection('Notices');
//notice list from snapshot
List<Notice>_noticeListFromSnapshot(QuerySnapshot snapshot){
return snapshot.documents.map((doc){
return Notice(
title:doc.data['title'] ?? '',
url: doc.data['url'] ?? '',
category: doc.data['noticecategory'] ?? 'General',
status: doc.data['status'] ?? 'unapproved',
dateTime: doc.data['dateTime'] ?? '',
noticeId: doc.data['noticeId'] ?? ''
);
}).toList();
}
Stream<List<Notice>>get notices{
return noticeCollection.snapshots().map(_noticeListFromSnapshot);
}
那么我该如何过滤未批准的通知并显示它们。
【问题讨论】:
-
I want to convert them 'approved'是什么意思 -
我想将通知状态更新为“已批准”
-
您想一次将 Firestore 中的所有“未批准”更新为“已批准”吗?
标签: firebase flutter dart google-cloud-firestore