'getting issue in Dart
addorRemCcToList(EmployeeList item) {
print('add or');
print(_ccToListSelected.length);
print(_tempccToListSelected.length);
if (_tempccToListSelected.contains(item)) {
_tempccToListSelected.remove(item);
} else {
_tempccToListSelected.add(item);
}
print(_tempccToListSelected.length);
print(_ccToListSelected.length);
notifyListeners();
}
so this is a method through which i'm adding or removing items in _tempccToListSelected this list but the issue is when i make changes in _tempccToListSelected this list this _ccToListSelected list get the same changes and i didn't event touched it as you can see in the picture it is the terminal showing the print result
Solution 1:[1]
You certainly have a line like this:
_tempccToListSelected = _ccToListSelected;
or the opposite.
This line don't copy list into another one but make a pointer to the other list (like in numerous language).
If you want to copy (duplicate) the liste use spread operator:
_tempccToListSelected = [..._ccToListSelected];
Solution 2:[2]
If you have code like this:
list1 = [];
list2 = list1;
this error is normal. You need give more information about this issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alaindeseine |
| Solution 2 | MalikSenpai |
