简体   繁体   English

FireBase - 使用用户身份验证时更新字段

[英]FireBase - update field when using user authentication

I am stuck with FireBase right now.我现在被 FireBase 卡住了。 I have a function that I use to change the color of a star icon in my test app.我有一个 function 用于更改测试应用程序中星形图标的颜色。 it works fine.它工作正常。 Now, I would like that when a user tap on the icon, it will update the value in the document in FireBase.现在,我希望当用户点击该图标时,它会更新 FireBase 文档中的值。

As I am starting from 4 weeks now to learn flutter, it is challenging.因为我现在是从 4 周开始学习 flutter,所以很有挑战性。 Many thanks for your help.非常感谢您的帮助。

void _toggleFlagInbox() {
    setState(() {
      if (_isUrgentInboxTask == "true") {

        _isUrgentInboxTask = "false";

        FirebaseFirestore.instance
            .collection("Users")
            .doc("tasks")
            .collection("tasks")
            .where("task_Status", isEqualTo: task_Inbox)
            .get()
            .then((res) {
          res.docs.forEach((result) {
            FirebaseFirestore.instance
                .collection("Users")
                .doc("tasks")
                .collection("tasks")
                .doc(result.id)
                .update({"important": "false"});
          });
        });


        FirebaseFirestore.instance
            .collection('Users')
            .doc(FirebaseAuth.instance.currentUser.uid)
            .collection('tasks')
            .docs
            .update({'important':"false"});

         

      } else {

        _isUrgentInboxTask = "true";
      }
    });

I have find.我找到了。 I copy what I am doing in case this help somebody else我复制我正在做的事情以防这对其他人有帮助

FirebaseFirestore.instance
        .collection('Users')
        .doc(
        FirebaseAuth.instance.currentUser.uid)
        .collection('inbox')
        .doc(document.id)
        .update({
        "important":"false"});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM