default_value_in_function_type
Parameters in a function type can't have default values.
Description
#The analyzer produces this diagnostic when a function type associated with a parameter includes optional parameters that have a default value. This isn't allowed because the default values of parameters aren't part of the function's type, and therefore including them doesn't provide any value.
Example
#The following code produces this diagnostic because the parameter p
has a
default value even though it's part of the type of the parameter g
:
dart
void f(void Function([int p = 0]) g) {
}
Common fixes
#Remove the default value from the function-type's parameter:
dart
void f(void Function([int p]) g) {
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。