For the Dart language when we pass a List
to a function as a parameter we pass its reference by default, which means we are passing and editing the original list.
This may cause confusion because it doesn't follow the same pattern in all languages, the Solitity language is an example of how this could be the oposite as default.
In the first test of the following example we can see how this happens and in the second test we see how to avoid it by simply calling .toList()
at the end of the original List
, creating a new reference by doing this.
To open this example on dartpad, follow dartpad link
The same applies to Maps
, here are the examples: dartpad link