So I have a situation where I have a parent list, and inside it has two more lists. So basically [[],[]].
Now, if I update someList[0][0] = ‘A’ automatically someList[1][0] updates.
Thankyou in advanced.
So I have a situation where I have a parent list, and inside it has two more lists. So basically [[],[]].
Now, if I update someList[0][0] = ‘A’ automatically someList[1][0] updates.
Thankyou in advanced.
2
Answers
You’ve basically provided no info, but if you add the same list to the parent list, then do an update to the inner lists, both will update "automatically", because it is the same list.. Variables store references.
If you don’t want that to happen, you need to make a copy of the list.
See this example:
https://dartpad.dev/?id=7104e40df1cfde463c32ff5ef264afaa
This below extension method might helpful for you:
Note: I just created it for only
List<int>
; you can modify it as per your needs.