use_ truncating_ division
Use truncating division.
Details
#DO use truncating division, '~/', instead of regular division ('/') followed by 'toInt()'.
Dart features a "truncating division" operator which is the same operation as division followed by truncation, but which is more concise and expressive, and may be more performant on some platforms, for certain inputs.
BAD:
var x = (2 / 3).toInt();
GOOD:
var x = 2 ~/ 3;
Enable
#
To enable the
use_truncating_division
rule, add
use_truncating_division
under
linter > rules
in your
analysis_options.yaml
file:
linter:
rules:
- use_truncating_division
If you're instead using the YAML map syntax to configure linter rules,
add
use_truncating_division: true
under
linter > rules:
linter:
rules:
use_truncating_division: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.