toUnmodifiable method
Creates an unmodifiable List containing all the elements of this iterable.
This method wraps the elements of the current iterable in an UnmodifiableListView, which prevents any modifications to the list such as adding, removing, or updating the elements.
-
Returns: An UnmodifiableListView containing all elements of this iterable.
-
Examples:
List<int> numbers = [1, 2, 3]; List<int> unmodifiableNumbers = numbers.toUnmodifiable(); print(unmodifiableNumbers); // UnmodifiableListView containing 1, 2, 3
Note: The returned list is a view of the original iterable. Any changes to the underlying iterable are reflected in the unmodifiable list. However, the list itself cannot be modified.
Implementation
List<T> toUnmodifiable() => UnmodifiableListView(this);