I'm adding another list items to new List and performing this code inside the setState(). But whenever I call this class in which the new list is initialized, list's previous entry gets disappear.. dont know why this happening. Also im new to flutter. thanks in advance.
List<String> myList = [];
inside build(stateful widget),
onTap: (){
setState((){
myList.add("newstring");
});}
you should copy objects in setState, in your case it should be
onTap: () {
setState((){
myList = [...state.myList, "newstring"];
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With