Bad state: No element Flutter / Dart Origin: On your device OSI layer 7 · Application Last updated 4 Nov 2026

Dart: Bad state: No element — .first, .last or .single on an empty list

You called .first, .last, .single or .reduce on an empty collection.

Exact message you may see Bad state: No elementStateError: Bad state: No elementBad state: Too many elementsBad state: Too few elementsUnhandled Exception: Bad state: No element
Seen on: Flutter

Meaning

These getters throw a StateError when the iterable is empty (or has more than one element for single). Use firstOrNull (Dart 3), isEmpty checks, or firstWhere(..., orElse: ...) to handle empty data, especially for lists filled from the network.

Common causes

  • list.first on an empty list
  • firstWhere without orElse and no match
  • Data not yet loaded when build runs
  • single on a list with several items
  • reduce on an empty iterable

⚡ Quick fix

  1. Check list.isNotEmpty before .first
  2. Use firstOrNull or firstWhere(test, orElse: () => default)
  3. Show a loading/empty state in the UI

Detailed fix by platform

Dart

  1. final first = items.firstOrNull; (Dart 3 package:collection extension in older SDKs)

How to diagnose

  1. Data — Empty at that moment?
  2. Getter — first/last/single/reduce?
  3. Fallback — orElse supplied?

🔧 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: Stream has already been listened to — Dart: Bad state: Stream has already been listened to (Flutter / Dart)Bad state: Stream has…Error: 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…Illegal argument in isolate message: object is unsendable — Dart: Invalid argument(s): Illegal argument in isolate message: object is unsendable - Library:'dart:async' Class: _Future@4048458 (Flutter / Dart)Illegal argument in i…LateInitializationError: Field has not been initialized — Dart: LateInitializationError: Field 'controller' has not been initialized (Flutter / Dart)LateInitializationErr…Non-nullable instance field must be initialized — Dart: Non-nullable instance field 'name' must be initialized. Try adding an initializer expression, or a generative constructor that initializes it, or mark it 'late' (Flutter / Dart)Non-nullable instance…Null check operator used on a null value — Dart/Flutter: Null check operator used on a null value (Flutter / Dart)Null check operator u…RangeError (index): Invalid value — Dart: RangeError (index): Invalid value: Valid value range is empty: 0 (Flutter / Dart)RangeError (index): I…Bad state…

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.