-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dart 3.0] GetIt can't detect T type properly #331
Comments
@subzero911 your analysis seems correct, although I don't think that this can be fixed by GetIt. I always recommend passing the Generic type explicitly because then there is no room for doubt @mraleph @munificent this comes sort of surprising, is that the intended consequence? |
First of all, it's strange that we can do call GetIt.instance(). Is it a callable class? I personally never did it. Do we actually need this assertion? |
Actually the assertion isn't about calling it this way, but if people call GetIt.instance() accidentially you get this type of eception too. final di = GetIt.instance;
// and then use it like
di<Mytype>().myMethod(); |
But writing |
That is true, but you don't register that many types and in my case I often register an abstract interface class with a selected implementation then I have to provide the type anyway
Am 29. Mai 2023, 11:21 +0200 schrieb Sergey Molchanovsky ***@***.***>:
… > I always recommend passing the Generic type explicitly because then there is no room for doubt
But writing GetIt.I.registerSingleton<MyControllerWithVeryLongName>(MyControllerWithVeryLongName()) every time is not concise.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
I'm not sure why this behavior is different in Dart 3.0. @stereotype441 or @eernst might know more. |
This fixes the now (from Dart SDK 3 onwards required) generic type annotation when calling `registerSingleton` from GetIt. Check the following issue: fluttercommunity/get_it#331 (comment)
This fixes the now (from Dart SDK 3 onwards required) generic type annotation when calling `registerSingleton` from GetIt. Check the following issue: fluttercommunity/get_it#331 (comment)
After the latest Flutter upgrade, registerSingleton inside of VoidCallback is not working anymore:
It worked before Dart 3.0. Now they probably have stricter type checking.
In runtime it crashes with the following error
The bug disappears when I explicitly indicate the type:
This bug appears in VoidCallback only, not in a plain code. It also can be fixed if I used:
() {}
instead of() =>
The reason behind: a generic by default takes the root return type (void), and Dart tries to put
void
intoT extends Object
constraint, and this apparently causes this assert to be falsely posivite:Any ideas on it?
The text was updated successfully, but these errors were encountered: