escamoteur / watch_it

MIT License
103 stars 8 forks source link

watch error: Couldn't infer type parameter 'T'. #21

Closed matthewkooshad closed 6 months ago

matthewkooshad commented 6 months ago

the watch example from the docs isn't working for me: final userName = watch(di<UserModel>()).name;

i'm trying similarly to that line in the build method of my widget: final screenTitle = watch(di<RootItemsScheme>()).screenTitle;

Couldn't infer type parameter 'T'.

Tried to infer 'RootItemsScheme' for 'T' which doesn't work: Type parameter 'T' is declared to extend 'Listenable' producing 'Listenable'. The type 'RootItemsScheme' was inferred from: Parameter 'target' declared as 'T' but argument is 'RootItemsScheme'.

Consider passing explicit type argument(s) to the generic.

from main: final gi = GetIt.instance; gi.registerSingleton<RootItemsScheme>(RootItemsScheme());

more info on screenTitle: String get screenTitle { switch (_itemType.value) { ...

_itemType is a ValueListenable in RootItemsScheme class, from which, i'm trying to return a string based on the value of it at the time i use the screenTitle getter.

matthewkooshad commented 6 months ago

i'm thinking the problem is that i'm trying to watch a string value rather than a notifier. i don't need a setter in this situation, it's only a getter logic that i need, and it's based on a ValueListenable, as noted. i was thinking i need the watch in order to see the latest value from the service, even though the service is producing a value based on the ValueListenable. please advise, thanks.

matthewkooshad commented 6 months ago

referencing that string getter that has logic based on a ValueListenable is not triggering a rebuild whenever the value changes of that the ValueListenable would be reflecting. the ValueListenable is reflecting a value from a ValueNotifier and that part is working fine. but, it's the logical string result that i'm needing reflected in the widget as the logic would produce a different value, is the part that i need to resolve.

escamoteur commented 6 months ago

Does UserModel implement tge Listenable interface? For instance by extending a ChangeNotifier? Am 13. Dez. 2023, 03:48 +0100 schrieb Matthew Kooshad @.***>:

the watch example from the docs isn't working for me: final userName = watch(di()).name; i'm trying similarly to that line in the build method of my widget: final screenTitle = watch(di()).screenTitle;

Couldn't infer type parameter 'T'. Tried to infer 'RootItemsScheme' for 'T' which doesn't work: Type parameter 'T' is declared to extend 'Listenable' producing 'Listenable'. The type 'RootItemsScheme' was inferred from: Parameter 'target' declared as 'T' but argument is 'RootItemsScheme'. Consider passing explicit type argument(s) to the generic. from main: final gi = GetIt.instance; gi.registerSingleton(RootItemsScheme()); — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

matthewkooshad commented 6 months ago

No. I didn't see that in the documentation noted. I'll look into doing that. Thanks

On Wed, Dec 13, 2023, 2:39 AM escamoteur @.***> wrote:

Does UserModel implement tge Listenable interface? For instance by extending a ChangeNotifier? Am 13. Dez. 2023, 03:48 +0100 schrieb Matthew Kooshad @.***>:

the watch example from the docs isn't working for me: final userName = watch(di()).name; i'm trying similarly to that line in the build method of my widget: final screenTitle = watch(di()).screenTitle;

Couldn't infer type parameter 'T'. Tried to infer 'RootItemsScheme' for 'T' which doesn't work: Type parameter 'T' is declared to extend 'Listenable' producing 'Listenable'. The type 'RootItemsScheme' was inferred from: Parameter 'target' declared as 'T' but argument is 'RootItemsScheme'. Consider passing explicit type argument(s) to the generic. from main: final gi = GetIt.instance; gi.registerSingleton(RootItemsScheme()); — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/escamoteur/watch_it/issues/21#issuecomment-1853483621, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTFMSLVYBXTLDU2VVZ6WGLYJFSULAVCNFSM6AAAAABASODJBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJTGQ4DGNRSGE . You are receiving this because you authored the thread.Message ID: @.***>

escamoteur commented 6 months ago

You can only watch an object that implements listenable otherwise watch_it wouldn't know that the object has changed. Am 13. Dez. 2023, 14:27 +0100 schrieb Matthew Kooshad @.***>:

No. I didn't see that in the documentation noted. I'll look into doing that. Thanks

On Wed, Dec 13, 2023, 2:39 AM escamoteur @.***> wrote:

Does UserModel implement tge Listenable interface? For instance by extending a ChangeNotifier? Am 13. Dez. 2023, 03:48 +0100 schrieb Matthew Kooshad @.***>:

the watch example from the docs isn't working for me: final userName = watch(di()).name; i'm trying similarly to that line in the build method of my widget: final screenTitle = watch(di()).screenTitle;

Couldn't infer type parameter 'T'. Tried to infer 'RootItemsScheme' for 'T' which doesn't work: Type parameter 'T' is declared to extend 'Listenable' producing 'Listenable'. The type 'RootItemsScheme' was inferred from: Parameter 'target' declared as 'T' but argument is 'RootItemsScheme'. Consider passing explicit type argument(s) to the generic. from main: final gi = GetIt.instance; gi.registerSingleton(RootItemsScheme()); — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/escamoteur/watch_it/issues/21#issuecomment-1853483621, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTFMSLVYBXTLDU2VVZ6WGLYJFSULAVCNFSM6AAAAABASODJBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJTGQ4DGNRSGE . You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

matthewkooshad commented 6 months ago

i just saw in the docs where i missed the extends ChangeNotifier for my class. thanks, and sorry that i missed that.

matthewkooshad commented 6 months ago

notice one example in your docs that doesn't have the extends ChangeNotifier. please confirm if that's for when just using watchValue as i was already trying.

class Model {
    final country = ValueNotifier<String>('Canada');
    ...
}
di.registerSingleton<Model>(Model());
escamoteur commented 6 months ago

In that case we can only watch the "country" property because it's a ValueNotifier which implements Listenable Am 15. Dez. 2023, 01:37 +0100 schrieb Matthew Kooshad @.***>:

notice one example in your docs that doesn't have the extends ChangeNotifier. please confirm if that's for when just using watchValue as i was already trying. class Model { final country = ValueNotifier('Canada'); ... } di.registerSingleton(Model()); — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>