Unsupported operation on an unmodifiable list

Unsupported operation: Cannot add to an unmodifiable list

Quick Answer

You tried to modify a list that is fixed-length or unmodifiable.

Why This Happens

In Dart, some lists are unmodifiable (e.g., const lists, List.unmodifiable). Attempting to add, remove, or modify elements throws an UnsupportedError. Create a new modifiable copy of the list before making changes.

The Problem

final items = const [1, 2, 3];
items.add(4); // Cannot modify const list!

The Fix

final items = const [1, 2, 3];
final mutableItems = List<int>.from(items);
mutableItems.add(4);

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: Unsupported operation: Cannot add to an unmodifiable list. This means the list cannot be modified.

  2. 2

    Find the cause

    Check if the list was created with const, List.unmodifiable, or returned from a method that provides an unmodifiable view.

  3. 3

    Apply the fix

    Create a mutable copy with List.from() or .toList() before modifying the list.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free