EN_raw_non_const_argument_for_const_parameter

  •                   Toolschevron_right
    
  •                   Diagnosticschevron_right
    
  •                   non_const_argument_for_const_parameter
    
                non_const_argument_for_const_parameter
    

Details about the 'non_const_argument_for_const_parameter' diagnostic produced by the Dart analyzer.

                more_vert
  •                       copyCopy link
    
  •                       bug_reportReport issue
    

Argument '{0}' must be a constant.

              Description

              #

              The analyzer produces this diagnostic when a parameter is
              annotated with the `mustBeConst`
               annotation and
              the corresponding argument is not a constant expression.

              Example

              #

              The following code produces this diagnostic on the invocation of
              the function `f` because the value of the argument passed to the
              function `g` isn't a constant:

                dart
import 'package:meta/meta.dart' show mustBeConst;
​
int f(int value) => g(value);
​
int g(@mustBeConst int value) => value + 1;
                content_copy

              Common fixes

              #

              If a suitable constant is available to use, then replace the argument
              with a constant:

                dart
import 'package:meta/meta.dart' show mustBeConst;
​
const v = 3;
​
int f() => g(v);
​
int g(@mustBeConst int value) => value + 1;
                content_copy

Was this page's content helpful?

                    thumb_up
                    thumb_down

                Unless stated otherwise, the documentation on this site reflects Dart 3.13.3. Report an issue.