riverpod
riverpod copied to clipboard
Detect obvious lacks of notifyListeners when doing mutations
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();
}
}