我一直在尝试创建一个由 Google 的 Firebase 提供支持的演示“Schedule-App”,但我在更新特定值时遇到了一些困难具有映射值的数组在 Firestore 的一侧。
如下图所示,我们想要实现什么 is onButtonPress
,这个具体值需要更新。
我创建了一个数据流并通过管理它StreamProvider
.
StreamProvider<DocumentSnapshot>.value(
value: FirebaseFirestore.instance.collection('schedule').doc(FirebaseAuth.instance.currentUser.uid).snapshots(),
我使用以下方法来更新数组的数据,但它不起作用。
Future<void> updateUserData(int index, String title, String text, int hour, bool check) async {
DocumentReference snapshots = FirebaseFirestore.instance.collection('schedule').doc(FirebaseAuth.instance.currentUser.uid);
snapshots.update({
['standard_schedule'][index]: {'title': title, 'text': text, 'hour': hour, 'check': check}
});
}
我应该对上面的方法进行哪些更改,以便每次按下按钮时更新 bool 值?
=================================================
解决方案(2020 年 10 月 24 日):
火库不提供更新索引处的数组元素的方法。您必须读取整个文档,修改内存中的数组,然后写入整个数组返回到文档。