Skip to content

notifier_build

v0.8.0 Warning Fix Riverpod State

Flags a class annotated with @riverpod (or @Riverpod(...)) that has no build method.

The generator turns a notifier’s build method into the provider’s create function. Without one, the build step fails — and the error points at the generated file, not the class that caused it. Catching this at analysis time names the actual class and offers a stub.

See also: Riverpod - Code generation

A notifier where the initial value was put in a field instead of a build method. The class looks complete, and the failure surfaces as a build_runner error inside counter.g.dart:

@riverpod
class Counter extends _$Counter { // LINT
int value = 0;
void increment() => value++;
}

build() is the initial state, and state is where it lives afterwards:

@riverpod
class Counter extends _$Counter {
@override
int build() => 0;
void increment() => state = state + 1;
}

A notifier that starts from other providers builds from them:

@riverpod
class CartTotal extends _$CartTotal {
@override
double build() {
final items = ref.watch(cartItemsProvider);
return items.fold(0, (sum, item) => sum + item.price);
}
}

Only @riverpod-annotated classes are checked. Functional providers have no build method by design and are never reported:

@riverpod
int counter(Ref ref) => 0;

The check is for a member named build, whatever its shape. A build field or getter satisfies it even though the generator wants a method.

This rule is in the core preset, so it is on with preset: core, preset: recommended or preset: opinionated.

To turn it off:

many_lints.yaml
rules:
notifier_build: false

To keep the rule on but skip certain paths, use per-rule exclude.