Skip to content

[Dart Fix] Proposal: expose the static type of a fragment #52664

@LongCatIsLooong

Description

@LongCatIsLooong

I'm writing a dart fix that migrates a constructor argument from a double? to a TextScaler?, the migrated code is hard to read in some cases.

Original Code:

Text(textScaleFactor: scaleFactor) where scaleFactor is an expression that can either be a double?, double, or null.

Desired migrated code:

if scaleFactor's static type is double? => Text(textScaler: switch (scaleFactor) { null => null, final factor => TextScaler.linear(factor), })
if scaleFactor's static type is double => Text(textScaler: TextScaler.linear(scaleFactor)
if scaleFactor's static type is null => Text()

Current migrated code:

Text(textScaler: switch (scaleFactor) { null => null, final factor => TextScaler.linear(factor), })

When scaleFactor is a double the current code is a lot harder to read than necessary, e.g.:

Text(textScaler: switch (2.0) { null => null, final factor => TextScaler.linear(factor), })

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.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions