RangeError (index): Invalid value Flutter / Dart Origin: On your device OSI layer 7 · Application Last updated 4 Nov 2026

Dart: RangeError (index): Invalid value: Valid value range is empty: 0

A list or string was indexed outside its bounds, often an empty list or an off-by-one in itemBuilder.

Exact message you may see RangeError (index): Invalid value: Valid value range is empty: 0RangeError (index): Invalid value: Not in inclusive range 0..2: 3RangeError (end): Invalid valueRangeError (length): Invalid valueUnhandled Exception: RangeError
Seen on: Flutter

Meaning

list[i] throws RangeError when i < 0 or i >= length. In widgets it usually comes from itemCount not matching the data, mutating a list while building, or reading [0] before data loads.

Common causes

  • Index equal to length (off by one)
  • Empty list accessed with [0]
  • itemCount larger than the list
  • List modified between itemCount and itemBuilder
  • Substring/sublist ends beyond length

⚡ Quick fix

  1. Guard with if (i < list.length)
  2. Set itemCount: items.length from the same list
  3. Show an empty state when the list is empty

Detailed fix by platform

Dart

  1. Use list.elementAtOrNull(i) (Dart 3) or i >= 0 && i < list.length

How to diagnose

  1. Index — Value vs length?
  2. List — Empty at that time?
  3. itemCount — Matches data?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Bad state: No element — Dart: Bad state: No element — .first, .last or .single on an empty list (Flutter / Dart)Bad state: No elementError: Couldn't resolve the package — Dart: Error: Couldn't resolve the package 'x' in 'package:x/x.dart' (Flutter / Dart)Error: Couldn't resol…FormatException: Unexpected character — Dart: FormatException: Unexpected character (at character 1) <!DOCTYPE html> — jsonDecode of an HTML page (Flutter / Dart)FormatException: Unex…Null check operator used on a null value — Dart/Flutter: Null check operator used on a null value (Flutter / Dart)Null check operator u…The argument type can't be assigned to the parameter type — Dart: The argument type 'String?' can't be assigned to the parameter type 'String' (Flutter / Dart)The argument type can…The getter/method isn't defined for the type — Dart: The getter 'name' isn't defined for the type 'User' / The method 'foo' isn't defined for the class (Flutter / Dart)The getter/method isn…type 'Null' is not a subtype of type 'String' — Dart: type 'Null' is not a subtype of type 'String' in type cast (Flutter / Dart)type 'Null' is not a …RangeErro…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.