As Irn said, there is no type for immutable lists in Dart, but this supplemental answer shows examples of creating immutable lists. You can't add, remove, or modify the list elements.
Compile time constant list variables
Use the const
keyword to create the list.
const myList = [1, 2, 3];
Note: Adding the optional const
keyword before the list literal is redundant when the variable is already const
.
const myList = const [1, 2, 3];
Compile time constant list values
If the variable can't be a const
, you can still make the value be const
.
final myList = const [1, 2, 3];
Runtime constant list
If you don't know what the list elements are until runtime, then you can use the List.unmodifiable()
constructor to create an immutable list.
final myList = List.unmodifiable([someElement, anotherElement]);