I have made the mistake of trying to use the return value of List.add and List.addAll many times, about once every week. I don't see any reason why they can't return the changed list, instead of nothing.
The new cascading function syntax, .., will of course allow the use of
myList..add(x)..addAll(y), but there is still no reason not to let people get the return value directly. Is the argument that users will be confused into thinking the original list is unchanged if the changed list is the return value?
I have now found the same error, made by a different coder than me. This confirms that this will be a common source of coding errors. This occurs commonly when producing a list with a literal or a constructor, and immediately adding items to it in the same expression. Here is the new error, showing how people expect a return value:
generatedTestPath = ['${debugMode}_${configuration["arch"]}']
.addAll(generatedTestPath);
You can see that this will occur often when trying to add a prefix to a list.
_This comment was originally written by nemequ...@gmail.com_
I would find that very confusing. If List.add returned a List, I would expect the return value to be a new instance and for the original value to be unmodified. For example, if I did something like
List<String> foo = ["one", "two", "three"];
List<String> bar = foo.addAll (["four", "five", "six"]);
I would expect foo to be ["one", "two", "three"] and bar to be ["one", "two", "three", "four", "five", "six"], not for both to be ["one", "two", "three", "four", "five", "six"].
FWIW I'm also not a big fan of having tons of methods return the receiver just to make chaining easier. Cascades for the win.
With cascades in the language, we generally don't make function return themselves for chaining.
So, no.
_Added NotPlanned label._
new List
@JayM96 This issue is closed, and your question is not about the subject of this issue. You are more likely to get a response if you post on StackOverflow. If you do, it would be better to include more details in the question, including the code you are asking about, and screenshots of the problem. You should post the question with the Flutter tag, not tagged Dart.