Invalid constant value in const constructor

Invalid constant value.

Quick Answer

A non-constant value was used in a const context.

Why This Happens

In Dart, const constructors require all arguments to be compile-time constants. If you pass a variable or function result to a const constructor, this error occurs. Remove the const keyword or ensure all values are compile-time constants.

The Problem

final color = Colors.blue;
const widget = Icon(Icons.star, color: color); // color is not const!

The Fix

const color = Colors.blue;
const widget = Icon(Icons.star, color: color); // Now color is const

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error: Invalid constant value. A non-const value is used where a compile-time constant is required.

  2. 2

    Find the cause

    Check the const constructor call for any arguments that are not compile-time constants (variables, function calls).

  3. 3

    Apply the fix

    Either make the value const, or remove the const keyword from the constructor call.

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