notifier_build
v0.8.0 Warning Fix Riverpod State
Flags a class annotated with @riverpod (or @Riverpod(...)) that has no build method.
Why use this rule
Section titled “Why use this rule”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:
@riverpodclass Counter extends _$Counter { // LINT int value = 0;
void increment() => value++;}build() is the initial state, and state is where it lives afterwards:
@riverpodclass Counter extends _$Counter { @override int build() => 0;
void increment() => state = state + 1;}A notifier that starts from other providers builds from them:
@riverpodclass CartTotal extends _$CartTotal { @override double build() { final items = ref.watch(cartItemsProvider); return items.fold(0, (sum, item) => sum + item.price); }}Known limitations
Section titled “Known limitations”Only @riverpod-annotated classes are checked. Functional providers have
no build method by design and are never reported:
@riverpodint 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.
Configuration
Section titled “Configuration”This rule is in the core preset, so it is on with preset: core,
preset: recommended or preset: opinionated.
To turn it off:
rules: notifier_build: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”protected_notifier_properties— A Notifier’s state, ref and future should not be used from outside the notifier.avoid_notifier_constructors— Prevent initialization logic in Notifier constructors.avoid_public_notifier_properties— Prevent public fields, getters, and setters on Notifier classes.avoid_build_context_in_providers— Providers outlive widgets, so they should not receive a BuildContext.