Skip to content

Dart compile errorFlutter: “Invalid constant value” / “Arguments of a constant creation must be constant expressions”

The build fails with Error: Invalid constant value (the IDE often says Arguments of a constant creation must be constant expressions, or Invalid constant value). Something marked const, often a widget like const Padding or const Text, contains a variable, a parameter, widget.something or a function call. Everything inside a const expression has to be known at compile time, and const on an outer widget applies to all of its children.

Short answer

Find the const nearest above the highlighted value and remove it, or move it down to the children that really are constant. If the value never changes, make it a constant instead (static const or a top-level const). Removing const is safe in ordinary widget code; it only gives up a small rebuild optimization. Where const is required (default parameter values, annotations, const variables), make the value itself constant instead.

Why the value isn’t constant, and the fix

  1. 01

    A variable inside a const widget

    “Either make all of the arguments constant expressions, or remove the const keyword to use the non-constant form of the constructor” Dart, const_with_non_constant_argument

    const Text(title) fails because title is only known at runtime. The same goes for context, Theme.of(context), MediaQuery.of(context) or widget.something inside a const widget. Drop const from that widget; keep it on siblings that are fully constant.

    // error
    const Padding(
      padding: EdgeInsets.all(16),
      child: Text(title),
    );
    
    // fixed
    Padding(
      padding: const EdgeInsets.all(16),
      child: Text(title),
    );
  2. 02

    const applied to a whole list of children

    children: const [ … ] makes every child constant. Adding one widget that uses a variable breaks the whole list. Remove const from the list and put it on the individual children that qualify.

    children: [
      const SizedBox(height: 8),
      Text(user.name),
      const Divider(),
    ],
  3. 03

    A value that should be a constant

    A padding or color kept in a final field or a getter can’t be used in const code. If it never changes, declare it const.

    class Spacing {
      static const double page = 16;
    }
    
    const EdgeInsets.all(Spacing.page)

Checked against the vendor’s docs on : Dart diagnostics: const_with_non_constant_argument.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Flutter “can’t be accessed in an initializer” · Flutter “The parameter can’t have a value of null” · Flutter “:app:compileFlutterBuildDebug” failed · Flutter “RangeError (index): Invalid value: Not in range”

Questions

More on this error

Should I just remove every const?

No need. Remove it only where the error points. If you want the analyzer to suggest const again wherever it is valid, enable prefer_const_constructors in analysis_options.yaml; Flutter’s default lints (flutter_lints 5 and later) no longer include it.

Why did it break after I edited one child?

Because const on a parent covers its children. The parent was valid while every child was constant; the new child made the whole expression non-constant.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.