use_ named_ constants
Details about the 'use_named_constants' diagnostic produced by the Dart analyzer.
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:
Duration d = const Duration(seconds: 0);
Common fixes
#
Replace the constructor invocation with a reference to the
known const
variable:
Duration d = Duration.zero;
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.