如何使用Firestore流自动更新列表?
在我的应用程序中,我现在使用“刷新功能”来更新提供商中的列表。当用户刷新时,我在提供商中调用RefReshList,并使用NotifyListeners()()可以更新我的UI。 (UI链接到列表_Myeleves)。 恐怕用户可能会多次使用此“刷新”按钮,在firebase上进行不必要的呼叫和“读取”,因此人为地增加了读数的数量,因此Firebase的成本。
这是代码:
Future<void> refreshEleveList() async {
final DocumentSnapshot<Map<String, dynamic>> docInfo =
await FirebaseFirestore.instance
.collection('familyAccounts')
.doc(_accountEmail.toLowerCase())
.get();
_mesEleves = (docInfo['mesEleves'] as List<dynamic>)
.map((data) => Eleve.fromMap(data))
.toList();
notifyListeners();
}
我一直在阅读很多有关流的信息,但是我只是在如何启动此流,聆听提供商文件中的firebase上的更改,以便对此进行更改,以便对”进行更改。 _myeleves”列表。 我想做的是,每次发生射击案件发生更改时,都会更新我的列表“ _myeleves”。有什么简单的方法吗?
我的提供商涵盖了整个应用程序(我在主文件中使用它)。我想到了添加了流媒体,但事实是,我不希望此流在用户获得身份验证等之前启动...首次下载了UserInfo。
现在:当用户登录时:从Firebase下载所有必要的信息,_Meseleves是其中之一(这是针对老师的)。每当新学生加入小组时,它都会修改Firebase,因此它应该将此信息流到教师帐户中的“ Myeleves”列表中。
有人可以帮忙吗?
In my app, I am now using a "refresh function" to update a list in Provider. When the user swipe, I call Refreshlist in my provider and with NotifyListeners() it updates my UI just fine. (The UI is linked to the list _myEleves).
I am afraid that users might use this "refresh" button too many times making unnecessary calls and "reads" on firebase and so increasing artificially the number of reads so the costs of Firebase.
Here is the code :
Future<void> refreshEleveList() async {
final DocumentSnapshot<Map<String, dynamic>> docInfo =
await FirebaseFirestore.instance
.collection('familyAccounts')
.doc(_accountEmail.toLowerCase())
.get();
_mesEleves = (docInfo['mesEleves'] as List<dynamic>)
.map((data) => Eleve.fromMap(data))
.toList();
notifyListeners();
}
I have been reading about STREAMS a lot, but I just can't get it right on how to start this stream, the listening to the changes on Firebase inside my PROVIDER file, so that changes will be made to "_myEleves" list.
What I want to do is that each time a change on firebase happens, it updates my list "_myEleves". Is there a simple way to do this ?
My Provider covers the whole app (I use it in the MAIN file). I thought of adding a StreamProvider, but the thing is I don't want this stream to start until user is authentified etc... and userInfo is first downloaded.
Right now : when user logs in : it downloads from firebase all necessary info, _mesEleves being one of them (This is for a teacher). Whenever a new student joins the group, it modifies firebase and so it should stream down this info into "myEleves" list on the teacher account.
Anybody can help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论