Questions tagged [riverpod-generator]

26 questions
4
votes
2 answers

How to generate providers using Riverpod generator?

With riverpod_generator, I can use: @riverpod int foo(FooRef ref) => 0; which is the equivalent of: final fooProvider = Provider((ref) => 0); But how can I do the same thing for other providers like FutureProvider, StateProvider, etc?
iDecode
  • 22,623
  • 19
  • 99
  • 186
3
votes
2 answers

What is the correct way of providing a GoRouter instance with riverpod?

I'm trying to provide an instance of GoRouter with riverpod. However, this results in the "The riverpod_generator package does not support ChangeNotifier values" warning to be displayed: My question is, what would be the correct way of achieving…
Alex Lomia
  • 6,705
  • 12
  • 53
  • 87
3
votes
1 answer

The argument type 'HWFamily' can't be assigned to the parameter type 'ProviderListenable'

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…
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
3
votes
1 answer

How to prevent provider from auto disposing when using riverpod_generator

I am using riverpod_generator and I don't see any way of keeping the provider alive. The generator code is actually equivalent to final fooProvider = FutureProvider.autoDispose((ref) async => 0); But in above code I could remove autoDispose but how…
iDecode
  • 22,623
  • 19
  • 99
  • 186
2
votes
1 answer

How can I implement MVVM pattern with riverpod annotation in Flutter?

I am trying to make MVVM architecture with riverpod annotation. And Here are some example code snippets. import ... part 'invite_customer_usecase.g.dart'; @riverpod class InviteCustomerUseCase extends _$InviteCustomerUseCase { final…
2
votes
0 answers

How to correctly override in tests the provider generated by Riverpod?

I have the repository and I generate provider for this repository like this: @riverpod class Repository extends _$Repository { @override String? build() { return null; } Future fetchData() async { state = "Hello World!"; …
2
votes
1 answer

Unable to access Riverpod provider state

I currently have a riverpod provider declared as follows: @riverpod class FeeInputData extends _$FeeInputData { @override Fee build() { return const Fee( id: 0, institutionId: 'nmb7588BVjhvnb', name: '', …
2
votes
1 answer

How can I create a "non-autodispose" provider with riverpod_annotation?

Observations if I create a provider using riverpod_annotation as follow import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'foo.g.dart'; @riverpod String foo(FooRef ref) => 'foo'; said provider will needlessly be a…
1
vote
1 answer

Usage of ref.read() and ref.watch() inside OnPressed function in Flutter

The Riverpod documentation clearly states that: The watch method should not be called asynchronously, like inside an onPressed of an ElevatedButton. Nor should it be used inside initState and other State life-cycles. In those cases, consider using…
1
vote
0 answers

Riverpod Builder Pass Initial Value and Label to Builder

I'm using Riverpod and Riverpod generator (great packages by the way), and I was wondering is there a way to pass a label AND an initial value to a generated Provider? There are lots of times where I want the Provider to hold a large Dart…
Grey
  • 331
  • 3
  • 11
1
vote
1 answer

Merge different states with Riverpod and Freezed

I have a page that needs two different API calls. I am applying the clean architecture to write the code and Riverpod as State Management. Then I am using the Freezed package to map the different states. How can I combine the different states? What…
1
vote
1 answer

Flutter: Disposing of resources in @riverpod generated provider

I am using riverpod_generator in my Flutter app to generate a provider for a controller that I use. The controller is actually a Notifier. I am wondering where is the correct place in the controller to set up the disposal of resources (in this case,…
user9661910
  • 29
  • 1
  • 2
1
vote
1 answer

how do I fix riverpod_lint error message 'If a provider depends on providers which specify "dependencies"...'

set up create a new project add the dependencies visible under additional information add the files below foos.dart import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'foos.g.dart'; @Riverpod(keepAlive: true) class Foos…
1
vote
1 answer

Flutter RIverpod changing state strangely

I have to state providers. The second one (listWithGlobalIDProvider) depends on the first one (currentListProvider) but the first one is independent. But Adding value to the second provider changes the first provider's value. I am calling the…
monzim
  • 526
  • 2
  • 4
  • 13
1
vote
0 answers

Error on generated file for AsyncNotifierProvider `.family` Riverpod providers

I wonder if I am overlooking something. When ever I try to generate the following via riverpod_annotation I'm getting the error below where it cannot find Family class. I'm pretty sure I'm doing something wrong, but I'm not sure what. I've deleted…
Chris King
  • 95
  • 1
  • 10
1
2