use_named_constants
Use the constant '{0}' rather than a constructor returning the same object.
Description
#The analyzer produces this diagnostic when a constant is created with the same value as a known const
variable.
Example
#The following code produces this diagnostic because there is a known const
field (Duration.zero
) whose value is the same as what the constructor invocation will evaluate to:
dart
Duration d = const Duration(seconds: 0);
Common fixes
#Replace the constructor invocation with a reference to the known const
variable:
dart
Duration d = Duration.zero;
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.