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
:
int divide(int x, int y) => (x / y).toInt();
Common fixes
#Use the integer division operator (~/
):
int divide(int x, int y) => x ~/ y;
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.