Add an element to the end of a list.
The add method appends a single element to the end of a growable List. The list's length increases by one after the operation. This method modifies the list in place and returns void.
This method only works on growable lists. Attempting to call add on a fixed-length list, such as one created by List.filled with growable set to false, will throw an UnsupportedError.
For adding multiple elements at once, use addAll which accepts an Iterable. For inserting an element at a specific index rather than the end, use the insert method.
| Name | Description | Optional |
|---|---|---|
value |
The element to add to the list. | No |
var list = [1, 2, 3];
list.add(4);
print(list); // [1, 2, 3, 4]