Skip to content

[Dart 3.0] GetIt can't detect T type properly #331

@subzero911

Description

@subzero911

After the latest Flutter upgrade, registerSingleton inside of VoidCallback is not working anymore:

image

It worked before Dart 3.0. Now they probably have stricter type checking.
In runtime it crashes with the following error
image

The bug disappears when I explicitly indicate the type:
image

This bug appears in VoidCallback only, not in a plain code. It also can be fixed if I used:
() {} instead of () =>

image

The reason behind: a generic by default takes the root return type (void), and Dart tries to put void into T extends Object constraint, and this apparently causes this assert to be falsely posivite:
image

Any ideas on it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions