Null check operator used on a null value

Null check operator used on a null value

Quick Answer

You used the ! operator on a variable that was null at runtime.

Why This Happens

In Dart, the null check operator (!) asserts that a value is non-null. When the value is actually null at runtime, this exception is thrown. You should use null-aware operators (?., ??) or add proper null checks before using the ! operator.

The Problem

String? name;
final length = name!.length; // name is null!

The Fix

String? name;
final length = name?.length ?? 0;

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: Null check operator used on a null value. This tells you the ! operator was applied to null.

  2. 2

    Find the cause

    Check the stack trace to find the exact line where ! was used, and determine why the variable was null at that point.

  3. 3

    Apply the fix

    Replace the ! operator with null-aware operators like ?. or ?? to safely handle the null case.

Got the actual stack trace?

Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.

Explain my error

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free