0

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 ?

1 Answer 1

2

Try this code, it should add items to list:


_firestore.collection("UsersTodos").doc(username).update({
    'userTodo': FieldValue.arrayUnion([_todoController.text]),
});
Sign up to request clarification or add additional context in comments.

2 Comments

It worked. Thanks a lot. But there is a problem. My data comes like [first,second,third] i want to seperate them. When i get them like listofDocumentSnap[index]['userTodo'] it is not coming 1 by 1 . Its comming like array i want to seperate them
I think this method won't work. I need to convert this like userTodo0 , userTodo1,userTodo2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.