Home > Mobile >  Flutter firebase adding new data
Flutter firebase adding new data

Time:01-10

I have a button which is create a new data for firebase. But when i change the data its updating , but i want to add a new one. For example , this is my set part;

 IconButton(
                    onPressed: () {
                      _firestore.collection("UsersTodos").doc(username).set({
                        'userTodo': [_todoController.text],
                      });
                    },
                    icon: Icon(Icons.add)),

When i enter another value to textfield my document is updating and change the value, i need to create an another value for that document.

enter image description here

Shall i loop this area with for loop ?

CodePudding user response:

Try this code, it should add items to list:


_firestore.collection("UsersTodos").doc(username).update({
    'userTodo': FieldValue.arrayUnion([_todoController.text]),
});
  •  Tags:  
  • Related