riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Detect obvious lacks of notifyListeners when doing mutations

Open rrousselGit opened this issue 1 year ago • 0 comments

Bad:

@riverpod
class Example extends _$Example {
  List<Item> build() => [];

  void addItem(Item item) {
    state.add(item); // Mutation but no notifyListeners()
    // works with variants, like `state.value = 42`
  }
}
@riverpod
class Example extends _$Example {
  Int build() => 0

  void doSomethingAsync(Item item) async {
    state++;
    await future;
    // Even though there is a notifyListeners, it is after an async gap.
    // The notifyListeners should be above the await
    notifyListeners();
  }
}

rrousselGit avatar Apr 08 '23 19:04 rrousselGit