Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

Dart Tutorial

Dart HOME Dart Intro Dart Get Started Dart Syntax Dart Output Dart Comments Dart Variables Dart final and const Dart Data Types Dart Numbers Dart Strings Dart String Interpolation Dart String Methods Dart Booleans Dart Type Conversion Dart Null Safety Dart late Dart Operators Dart Arithmetic Dart Assignment Dart Comparison Dart Logical Dart Type Test Dart Null Operators Dart Cascade Dart If...Else Dart Switch Dart While Loop Dart For Loop Dart Break/Continue

Dart Collections

Dart Lists Dart Access List Items Dart Change List Items Dart Loop Lists Dart List Methods Dart Sets Dart Maps Dart Access Map Items Dart Loop Maps Dart Collection if/for Dart Spread Operator

Dart Functions

Dart Functions Dart Parameters Dart Named Parameters Dart Return Values Dart Arrow Functions Dart Anonymous Functions Dart Closures Dart Scope Dart Recursion

Dart Classes

Dart OOP Dart Classes/Objects Dart Constructors Dart Named Constructors Dart Factory Constructors Dart Getters and Setters Dart Static Members Dart Inheritance Dart Abstract Classes Dart Interfaces Dart Mixins Dart Extension Methods Dart Enums Dart Generics

Dart 3 Features

Dart Records Dart Patterns Dart Switch Expressions Dart Sealed Classes Dart Class Modifiers

Dart Errors

Dart Exceptions Dart Custom Exceptions

Dart Async

Dart Async Intro Dart Futures Dart async/await Dart Streams Dart Isolates

Dart Libraries

Dart Imports Dart Packages Dart Math Dart Dates Dart JSON Dart RegExp Dart User Input Dart Files Dart Testing

Dart Examples

Dart Examples Dart Exercises


Dart Change List Items


Share

Change an Item

To change the value of an item, assign a new value to its index:

Example

void main() {
  final fruits = ['apple', 'banana', 'cherry'];
  fruits[1] = 'blackcurrant';
  print(fruits);
}
Try it Yourself »

Result:

[apple, blackcurrant, cherry]

The list is final, but you can still change its items.

final only means that the variable always points to the same list.


Add Items

The add() method adds one item to the end of the list:

Example

void main() {
  final fruits = ['apple', 'banana', 'cherry'];
  fruits.add('orange');
  print(fruits);
}
Try it Yourself »

Result:

[apple, banana, cherry, orange]

The addAll() method adds all the items of another list to the end:

Example

void main() {
  final fruits = ['apple', 'banana'];
  final tropical = ['mango', 'pineapple', 'papaya'];
  fruits.addAll(tropical);
  print(fruits);
}
Try it Yourself »

Result:

[apple, banana, mango, pineapple, papaya]


Insert Items

The insert() method adds an item at a given index.

The items after it move one place to the right:

Example

void main() {
  final fruits = ['apple', 'banana', 'cherry'];
  fruits.insert(1, 'orange');
  print(fruits);
}
Try it Yourself »

Result:

[apple, orange, banana, cherry]

Use index 0 to add an item at the start of the list.


Remove Items

The remove() method removes the first item with the given value:

Example

void main() {
  final fruits = ['apple', 'banana', 'cherry', 'banana'];
  fruits.remove('banana');
  print(fruits);
}
Try it Yourself »

Result:

[apple, cherry, banana]

remove() returns true if it found and removed the item, and false if not.

The removeAt() method removes the item at a given index, and removeLast() removes the last item.

Both methods return the item they removed:

Example

void main() {
  final fruits = ['apple', 'banana', 'cherry', 'kiwi'];
  final removed = fruits.removeAt(1);
  print('Removed $removed');
  print(fruits);
  final last = fruits.removeLast();
  print('Removed $last');
  print(fruits);
}
Try it Yourself »

Result:

Removed banana
[apple, cherry, kiwi]
Removed kiwi
[apple, cherry]

The removeWhere() method removes every item that matches a test.

The test is a small function that gets an item and returns true to remove it:

Example

void main() {
  final scores = [45, 82, 37, 90, 61];
  scores.removeWhere((score) => score < 50);
  print(scores);
}
Try it Yourself »

Result:

[82, 90, 61]

The => arrow is a short way to write a function that returns one value.

You will learn more in the Dart Arrow Functions chapter.


Clear the List

The clear() method removes all items.

The list still exists, but it is empty:

Example

void main() {
  final fruits = ['apple', 'banana', 'cherry'];
  fruits.clear();
  print(fruits);
  print(fruits.length);
}
Try it Yourself »

Result:

[]
0

Note: The methods that add or remove items only work on growable lists.

On a fixed-length or const list, they throw an error (see Dart Lists).



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.