non_const_argument_for_const_parameter
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;
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;
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。