0Pricing
Dart Academy · Lesson

Adding, Removing, and Updating Items

Mutate a list safely.

Adding, Removing, and Updating Items is a free Dart Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Lists Can Change

Most Dart lists are growable, meaning you can add and remove items after creating them. That makes them perfect for data that changes over time.

Add to the End

The add method appends one item to the back of the list. The list grows by one and the new item takes the last index.

var todos = ['wake up'];
todos.add('code');

Add Many at Once

Need to append several items? Use addAll with another list, and every item joins the end in order.

todos.addAll(['eat', 'sleep']);

Insert Anywhere

Place an item at an exact spot with insert. Everything from that index onward shifts one step to the right.

todos.insert(0, 'stretch');

Update by Index

Change an existing item by assigning to its index. This overwrites whatever was there before, keeping the same position.

todos[1] = 'write tests';

Remove a Value

The remove method deletes the first item equal to the value you pass. It returns true if it found and removed something.

todos.remove('sleep');

Remove by Position

To delete by index instead of value, use removeAt. It pulls out that slot and hands the removed item back to you.

todos.removeAt(0);

Remove the Last Item

removeLast pops off the final item quickly, like the top of a stack. It also returns the value it removed.

var done = todos.removeLast();

Clear Everything

Empty a list in one move with clear. The list stays usable; it just drops down to zero items.

todos.clear();
print(todos.length); // 0

Fixed-Length Lists

Some lists are fixed-length and cannot grow or shrink. Calling add on one of those throws an error at runtime.

Conditional Removal

Drop every item matching a rule with removeWhere. Pass a test, and each item that returns true gets deleted.

var nums = [1, 2, 3, 4];
nums.removeWhere((n) => n.isEven);

Quick Check

You want to delete the item sitting at index 2. Which call does it?

Recap

You can now reshape a list freely: add, insert, update by index, and remove by value or position. Mutating lists is second nature now. 🛠️

Frequently asked questions

Is the “Adding, Removing, and Updating Items” lesson free?

Yes — the full text of “Adding, Removing, and Updating Items” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.

What will I learn in “Adding, Removing, and Updating Items”?

Mutate a list safely. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Dart Academy?

No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Adding, Removing, and Updating Items” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Dart Academy lesson?

Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Creating Lists and Indexing
  2. Adding, Removing, and Updating Items
  3. Searching and Sorting Lists
  4. Transforming With map, where, and toList
← Back to Dart Academy