Contents

use_truncating_division

Contents

Use truncating division.

This rule is available as of Dart 3.6.

This rule has a quick fix available.

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:

dart
var x = (2 / 3).toInt();

GOOD:

dart
var x = 2 ~/ 3;

Usage

#

To enable the use_truncating_division rule, add use_truncating_division under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - use_truncating_division