Reputation: 22306
I'm following the example in https://carltonaikins.me/how-to-use-riverpod-2-generator-in-your-flutter-project and I now have ...
@riverpod
class HW extends _$HW {
@override
dynamic build(foo) => 'HelloWorld'; // without foo, I get build dynamic Function() is not a valid override of build (dynamic Function(dynamic)
}
return Consumer(builder: (context, ref, child) {
var s1 = ref.watch(hWProvider); // gives The argument type 'HWFamily' can't be assigned to the parameter type 'ProviderListenable<dynamic>'.
var s2 = ref.watch(hWProvider.notifier); // gives The getter 'notifier' isn't defined for the type 'HWFamily'.
var s3 = ref.watch(hWProvider.call('foo'); // seems to work
...
I don't understand if I'm doing something wrong, or the example I'm following is somehow out of date? If the latter, is there a better example to follow?
What is the significance of foo
?
Versions:-
EDIT
I suspect this might be a problem with the build process. I killed the watch process, deleted main.g.dart, removed "foo", restarted the watch, and now everything works as it should. Somehow the "foo" (which I added to get past the override error) was creating a Family.
Upvotes: 5
Views: 2246
Reputation: 277477
The build
method of your provider has parameters. As such, when listening to your provider you need to pass those providers:
ref.watch(hWProvider(foo));
If you don't need that parameter, remove it from your build
method. Then you will be able to listen to the provider without passing any value.
Upvotes: 8