I can sort a list like this in Dart:
final myList = [6, 3, 7, 1, 0, 2];
myList.sort();
However, this is a destructive sort since it mutates it in place. I'd like to do something like this:
final myList = [6, 3, 7, 1, 0, 2];
final newList = myList.sorted();
where my list stays the same but newList
contains the sorted list. Dart apparently doesn't have this functionality, so how do I implement that myself?
In searching for the answer to this question my main struggle was knowing the proper way to copy a list, which wasn't as obvious as it seems like it should be. I found the answer to that, so I am also posting an answer to my original question below, Q&A style.