prefer_ int_ literals
Details about the 'prefer_int_literals' diagnostic produced by the Dart analyzer.
Unnecessary use of a 'double' literal.
Description
#
The analyzer produces this diagnostic when a
double literal's value has a fractional part of 0
(such as 8.0) and is used where the context type
is double.
In these cases, you can use an int literal
instead, because it would evaluate to the same
double value.
Examples
#
The following code produces this diagnostic because the
literal 8.0 is used to initialize a variable of
type double, but its value has a fractional part
of 0:
double d = 8.0;
The following code produces this diagnostic because the
literal 7.1e2 evaluates to 710.0,
which has a fractional part of 0, and is used to
initialize a variable of type double:
double d = 7.1e2;
Common fixes
#
Replace the double literal with an equivalent
int literal:
double d = 8;
double d = 710;
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.