riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

riverpod_generator: Make `build` optional in the class syntax

Open rrousselGit opened this issue 2 years ago • 3 comments

Support:

@riverpod
class Foo extends _$Foo {
}

Foo value = ref.watch(fooProvider);

@riverpod
class Foo extends _$Foo {
  void build() {this.a = ref.watch(something);}
}

Foo value = ref.watch(fooProvider);

@riverpod
class Foo extends _$Foo {
  Future<void> build() async {this.a = ref.watch(something);}
}

AsyncValue<Foo> value = ref.watch(fooProvider);
Foo value = ref.watch(fooProvider.notifier);

rrousselGit avatar Feb 17 '23 16:02 rrousselGit

@rrousselGit Do you mind if I create a PR doing this?

I have some experience with code generation and I think this one should be simple to implement.

adsonpleal avatar Mar 30 '23 18:03 adsonpleal

I still need to think this through. It's unclear to me whether this is truly desired.

rrousselGit avatar Mar 30 '23 18:03 rrousselGit

Cool! I'll keep watching this issue then.

adsonpleal avatar Mar 30 '23 19:03 adsonpleal