Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter firebase adding new data

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Shall i loop this area with for loop ?

>Solution :

Try this code, it should add items to list:


_firestore.collection("UsersTodos").doc(username).update({
    'userTodo': FieldValue.arrayUnion([_todoController.text]),
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading