DEV Community

Leonard Kioi kinyanjui
Leonard Kioi kinyanjui

Posted on

How to fix Dart Lang Error: RangeError (index): Index out of range: no indices are valid: 0

In C like languages like JS, its a common operation to assign a value to an array in a for loop at a given index using []. Like this:

JS Forloop

With Dart lang trying this:

Dart Incorrect For Loop

You get the error: RangeError (index): Index out of range: no indices are valid: 0

The solution is to use List's insert method .insert(i, value) or .add(value).

Dart Lang using add in for loop

Top comments (0)