Skip to content

Bug Report: Dart analyzer error on valid Duration comparison in async function #61062

Open
@khalilovnn

Description

@khalilovnn

Bug Report: Dart analyzer error on valid Duration comparison in async function

Title

Dart analyzer error: "Conditions must have a static type of 'bool'" on valid Duration comparison in async function

Description

In a Flutter/Dart project, the analyzer throws the following error on a valid comparison of integer values inside an async function:

Conditions must have a static type of 'bool' • non_bool_condition

Minimal Reproducible Example

Future<void> checkLag() async {
  final Duration lag = await getLag();
  final int lagSeconds = lag.inSeconds;
  final int maxAllowedSeconds = 5 * 60;
  if (lagSeconds > maxAllowedSeconds) {
    print('High lag');
  }
}

Future<Duration> getLag() async => Duration(seconds: 400);

Analyzer Output

error • Conditions must have a static type of 'bool' • lib/example.dart:6:7 • non_bool_condition

Expected Behavior

The analyzer should not report an error for comparing two int values in an if condition. The code compiles and runs correctly.

Actual Behavior

The Dart analyzer reports an error, even though the condition returns a bool and the code is valid.

Additional Information

  • Flutter version: [please insert your Flutter version]
  • Dart SDK version: [please insert your Dart SDK version]
  • Operating system: macOS 14.4.0 (Darwin 24.4.0)
  • Tried various workarounds: moving the condition to a sync function, using explicit type casts, comparing Duration directly and via inSeconds—the error persists.
  • The error appears only in async functions when comparing values obtained via await.

Screenshot / Logs

(Please attach a screenshot of the error from your terminal or IDE)


What remains to be done

  • Please investigate why the analyzer reports a non_bool_condition error for a valid boolean comparison in an async function.
  • Confirm if this is a known issue or a new bug in the Dart analyzer.
  • Suggest a workaround or provide a fix in a future Dart/Flutter SDK release.
  • Optionally, provide guidance on how to suppress this specific false positive if a fix is not immediately available.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions