Skip to content

use_if_null_to_convert_nulls_to_bools has quickfix which does not respect operator precedence of the surrounding expression #61507

@Chaos02

Description

@Chaos02

If this is a bug report, please help us by providing:

Example:

  SingleChildRenderObjectWidget createArticleImage(Orientation orientation) => article!.image?.isNotEmpty == true && orientation == Orientation.portrait
        ? Padding(
            padding: const EdgeInsets.only(left: 5, bottom: 8, right: 5),
            child: integrationTestMode
                ? Image.asset('assets/icon/logo.png') // Use a static image during tests
                : Image.network('$baseImgUrl${article!.imageMobile!}'),
          )
        : emptyBox;

this correctly triggers the Dart Analyzer use_if_null_to_convert_nulls_to_bools lint.

After applying it the code looks like this:

  SingleChildRenderObjectWidget createArticleImage(Orientation orientation) => article!.image?.isNotEmpty ?? false && orientation == Orientation.portrait
        ? Padding(
            padding: const EdgeInsets.only(left: 5, bottom: 8, right: 5),
            child: integrationTestMode
                ? Image.asset('assets/icon/logo.png') // Use a static image during tests
                : Image.network('$baseImgUrl${article!.imageMobile!}'),
          )
        : emptyBox;

BUT it registers the && orientation == Orientation.portrait part as dead code (which is false, since nullable.isNotEmpty == true is the same as nullable.isNotEmpty ?? false

Dart SDK version: 3.9.2 (stable) (Wed Aug 27 03:49:40 2025 -0700) on "windows_x64"

Flutter 3.35.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision a402d9a437 (13 days ago) • 2025-09-03 14:54:31 -0700
Engine • hash 672c59cfa87c8070c20ba2cd1a6c2a1baf5cf08b (revision ddf47dd3ff) (12 days ago) • 2025-09-03 20:02:13.000Z
Tools • Dart 3.9.2 • DevTools 2.48.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-quick-fixIssues with analysis server (quick) fixestype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions