fieldValue.Increment(int)不会降低火焰扑来的值

发布于 2025-01-22 14:55:43 字数 603 浏览 3 评论 0原文

试图降低火灾中的价值。但是以下方法无效。

int fastDur = -20;

void cancelHours() async {
  return usersRef.doc(firebaseAuth.currentUser!.uid).collection('posts')
    .orderBy('datePublished', descending: true)
    .limit(1).get().then((querySnapshot) {
  return querySnapshot.docs.forEach((element) {
    usersRef
        .doc(firebaseAuth.currentUser!.uid).collection('posts')
        .doc(element.reference.id)
        .update({"totalTime": FieldValue.increment(fastDur)});
    });
  });
 }

但是,如果我将'-20'放在方法fieldValue.increment(-20)中,则可以工作。但是,众所周知,我无法将其进行硬编码,因为FastDur具有用户选择的不同值。请帮忙。

trying to decrement a value in firestore. but the below method does not work.

int fastDur = -20;

void cancelHours() async {
  return usersRef.doc(firebaseAuth.currentUser!.uid).collection('posts')
    .orderBy('datePublished', descending: true)
    .limit(1).get().then((querySnapshot) {
  return querySnapshot.docs.forEach((element) {
    usersRef
        .doc(firebaseAuth.currentUser!.uid).collection('posts')
        .doc(element.reference.id)
        .update({"totalTime": FieldValue.increment(fastDur)});
    });
  });
 }

however, if I put '-20' into the method FieldValue.increment(-20) then it works. But as you all know, I cannot hardcode it as the fastDur has different values that user chooses. please, help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2025-01-29 14:55:43

使用firestore buildin询问方法

await _firestore.collection("Customers").doc(_auth.currentUser!.uid)
      .collection("Cart").doc(productid).update({
    'Quantity': FieldValue.increment(-1),
  })

Use Firestore buildin query method

await _firestore.collection("Customers").doc(_auth.currentUser!.uid)
      .collection("Cart").doc(productid).update({
    'Quantity': FieldValue.increment(-1),
  })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文