Generate Stateprovider using riverpod_generator #1725
-
I'd like to generate |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
StateProvider is simple without the generator. I'm curious why you are wanting to generate it specifically. The generator makes StateNotifier providers simpler by letting you define methods directly on a class and not splitting up the definition of the class and the definition of the provider. You can freely use regular riverpod and generated riverpod together. |
Beta Was this translation helpful? Give feedback.
-
There is no plan for now to have a StateProvider equivalent in the code generator. Making a class and generating a |
Beta Was this translation helpful? Give feedback.
-
There is a package to generated the equivalent of the https://pub.dev/packages/riverpod_state_provider_annotation # main.dart
import 'package:riverpod_state_provider_annotation/riverpod_state_provider_annotation.dart';
part 'main.g.dart';
part 'main.rsp.dart';
@RiverpodStateProvider()
int myState() {
return 0;
}
ref.watch(myStateProvider);
ref.read(myStateProvider.notifier).state++;
ref.read(myStateProvider.notifier).update((state) => state + 1);
ProviderScope(
overrides: [
myStateProvider.overrideWithValue(10),
],
) It still has some limitations but for simple usages (usually the case for |
Beta Was this translation helpful? Give feedback.
StateProvider is simple without the generator. I'm curious why you are wanting to generate it specifically. The generator makes StateNotifier providers simpler by letting you define methods directly on a class and not splitting up the definition of the class and the definition of the provider.
You can freely use regular riverpod and generated riverpod together.