Skip to content

missing_provider_scope

v0.8.0 Warning Fix Riverpod State

Flags a call to runApp() whose root widget is not a ProviderScope. Riverpod keeps all provider state inside a ProviderScope, so an app without one at the root cannot read any provider.

Nothing about a missing ProviderScope fails to compile. The app builds, launches, and then throws on the first ref.watch or ref.read it reaches — often deep in a screen the developer did not open while testing. This rule turns a runtime crash into an analysis-time warning.

See also: Riverpod - Getting started

void main() {
runApp(MyApp());
}
void main() {
runApp(ProviderScope(child: MyApp()));
}
// An externally-owned container is also a valid scope:
void mainWithContainer() {
final container = ProviderContainer();
runApp(
UncontrolledProviderScope(
container: container,
child: MyApp(),
),
);
}

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:
missing_provider_scope: false

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