default_value_on_required_parameter
Required named parameters can't have a default value.
Description
#The analyzer produces this diagnostic when a named parameter has both the
required
modifier and a default value. If the parameter is required, then
a value for the parameter is always provided at the call sites, so the
default value can never be used.
Example
#The following code generates this diagnostic:
dart
void log({required String message = 'no message'}) {}
Common fixes
#If the parameter is really required, then remove the default value:
dart
void log({required String message}) {}
If the parameter isn't always required, then remove the required
modifier:
dart
void log({String message = 'no message'}) {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。