What makes this a fixed-length list in Dart?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In Dart, a list is fixed-length when its size cannot be changed after creation. That does not mean the elements are immutable. It means operations that change the number of slots, such as add, remove, or insert, are not allowed. The key detail is usually whether the list was created with growable: false or by an API that returns a fixed-size list.
Fixed-Length Does Not Mean Read-Only
This is the first important distinction. A fixed-length list still lets you update existing positions:
What you cannot do is change its length:
So the fixed-length property is about structure, not about element mutability.
What Actually Makes It Fixed-Length
The most common reason is the constructor or factory you used. For example, List.filled creates a fixed-length list unless you explicitly pass growable: true.
At creation time both lists have length 3, but only the second one can later change size. That growable flag is the practical difference.
Other APIs also return fixed-length lists by design, especially when the result represents a known-size structure rather than a growable collection.
How to Tell in Practice
If you can assign to list[index] but add or remove throws UnsupportedError, you are dealing with a fixed-length list.
Example:
This behavior is intentional. Dart differentiates between changing element contents and changing collection size.
Fixed-Length Versus Unmodifiable
Another easy confusion is mixing up fixed-length lists with unmodifiable lists. They are not the same thing.
A fixed-length list:
- allows replacing existing elements
- does not allow changing length
An unmodifiable list:
- does not allow changing elements
- does not allow changing length
That means this is stricter than fixed-length:
If your code throws on element assignment itself, the list is likely unmodifiable, not merely fixed-length.
When Fixed-Length Lists Make Sense
Use fixed-length lists when the shape of the data is known in advance and should not change, such as:
- RGB channels
- game board rows with fixed width
- small numeric vectors
- lookup structures with stable size
They communicate intent. The code says, "this collection has exactly this many positions."
Common Pitfalls
- Assuming fixed-length means the elements themselves cannot change.
- Forgetting that
List.filledis fixed-length unlessgrowable: trueis supplied. - Confusing fixed-length lists with unmodifiable lists.
- Calling
add,insert, orremoveand being surprised byUnsupportedError. - Choosing a fixed-length list when the algorithm naturally needs to grow or shrink the collection.
Summary
- A fixed-length list in Dart has a size that cannot change after creation.
- You can usually still modify existing elements by index.
- The most common cause is creating the list with
growable: false, whichList.filleduses by default. - Fixed-length is different from unmodifiable.
- The deciding question is simple: can the number of elements change or not.
Related reading
- What .NET collection provides the fastest search
- What problem does IStructuralEquatable and IStructuralComparable solve?
- What python code generates all possible groupings trees for binary operators
- What real world uses of the Stack object .Net have you used
- What the iteration cost on a HashSet also depend on the capacity of backing map?
- What type of heap is used and time complexity of stdpriority_queue in c?
- What would a frozen dict be?
- What's a fast and stable algorithm for a random path in a node graph?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.