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

**Code:** `RangeError (index): Invalid value` · **Category:** Flutter / Dart · **Seen on:** Flutter

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/flutter/range-error-invalid-value)
