use_truncating_division
Use truncating division.
Description
#The analyzer produces this diagnostic when the result of dividing two
numbers is converted to an integer using toInt
.
Dart has a built-in integer division operator that is both more efficient and more concise.
Example
#The following code produces this diagnostic because the result of dividing
x
and y
is converted to an integer using toInt
:
dart
int divide(int x, int y) => (x / y).toInt();
Common fixes
#Use the integer division operator (~/
):
dart
int divide(int x, int y) => x ~/ y;
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。