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");
});}
CodePudding user response:
-> You Perform This Type Exaple Dart Pad EX:
void main() {
List<String> OneData = ['one','two','three'];
List<String> TwoData = [];
TwoData.add('one');
print(TwoData);
}
CodePudding user response:
you should copy objects in setState, in your case it should be
onTap: (){
setState((){
myList = [...state.myList, "newstring"];
})
;}