ImmutableList<T> class

A list that cannot be modified after it's created.

This is a wrapper around a standard Dart list that provides an unmodifiable view of the original list. This ensures that the underlying list cannot be changed once the ImmutableList object has been constructed.

Example:

final immutableList = ImmutableList([1, 2, 3]);
print(immutableList.first); // prints 1
Implemented types
Available extensions

Constructors

ImmutableList.new(List<T> items)
Constructs an ImmutableList.

Properties

first → T
Gets the first element in the list.
no setteroverride
firstOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The first element of this iterator, or null if the iterable is empty.
no setter
hashCode int
The hash code for this object.
no setteroverride
indexed Iterable<(int, T)>

Available on Iterable<T>, provided by the IterableExtensions extension

Pairs of elements of the indices and elements of this iterable.
no setter
isEmpty bool
Returns true if there are no elements in this collection.
no setteroverride
isNotEmpty bool
Returns true if there is at least one element in this collection.
no setteroverride
items UnmodifiableListView<T>
Provides an unmodifiable view of the items.
no setter
iterator Iterator<T>
A new Iterator that allows iterating the elements of this Iterable.
no setteroverride
last → T
Gets the last element in the list.
no setteroverride
lastOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The last element of this iterable, or null if the iterable is empty.
no setter
length int
Returns the number of items in the list.
no setteroverride
nonNulls Iterable<T>

Available on Iterable<T?>, provided by the NullableIterableExtensions extension

The non-null elements of this iterable.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → T
Gets the single element in the list. Throws an error if the list has more than one item.
no setteroverride
singleOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The single element of this iterator, or null.
no setter
wait Future<List<T>>

Available on Iterable<Future<T>>, provided by the FutureIterable extension

Waits for futures in parallel.
no setter

Methods

any(bool test(T)) bool
Checks if any item in the list satisfies the provided test.
override
asNameMap() Map<String, T>

Available on Iterable<T>, provided by the EnumByName extension

Creates a map from the names of enum values to the values.
byName(String name) → T

Available on Iterable<T>, provided by the EnumByName extension

Finds the enum value in this list with name name.
cast<R>() Iterable<R>
Casts the items of the list to the desired type R.
override
contains(Object? element) bool
Determines if the list contains the provided element.
override
elementAt(int index) → T
Returns the element at the specified index.
override
elementAtOrNull(int index) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The element at position index of this iterable, or null.
every(bool test(T)) bool
Checks if every item in the list satisfies the provided test.
override
expand<T0>(Iterable<T0> f(T)) Iterable<T0>
Expands each element into zero or more elements.
override
firstWhere(bool test(T), {T orElse()?}) → T
Gets the first element that satisfies the given predicate test. If none are found, it calls the orElse function if provided.
override
fold<T0>(T0 initialValue, T0 combine(T0, T)) → T0
Accumulates value starting with initialValue and applying combine for each element in order.
override
followedBy(Iterable<T> other) Iterable<T>
Appends all elements of other to the end of this iterable's elements.
override
forEach(void f(T)) → void
Applies the function f to each element of this collection.
override
join([String separator = ""]) String
Converts the items in the list to a string and concatenates them using the provided separator.
override
lastWhere(bool test(T), {T orElse()?}) → T
Gets the last element that satisfies the given predicate test. If none are found, it calls the orElse function if provided.
override
map<T0>(T0 f(T)) Iterable<T0>
Applies the function f to each element in the list and returns a new iterable with elements of type T0.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(T combine(T, T)) → T
Reduces the elements in the list to a single value using the combine function.
override
singleWhere(bool test(T), {T orElse()?}) → T
Gets the single element that satisfies the given predicate test. If none are found, it calls the orElse function if provided.
override
skip(int count) Iterable<T>
Skips the first count elements.
override
skipWhile(bool test(T)) Iterable<T>
Skips while elements satisfy the given predicate test.
override
take(int count) Iterable<T>
Takes the first count elements.
override
takeWhile(bool test(T)) Iterable<T>
Takes while elements satisfy the given predicate test.
override
toList({bool growable = true}) List<T>
Returns a list representation of the iterable.
override
toSet() Set<T>
Returns a set representation of the iterable.
override
toString() String
Returns a string representation of the list.
override
where(bool test(T)) Iterable<T>
Filters the elements in the list based on the predicate test.
override
whereType<T1>() Iterable<T1>
Returns an iterable of objects of type T, where T is a subtype of T.
override

Operators

operator ==(Object other) bool
The equality operator.
override