Skip to main content

prefer-provider-extensions

added in: 1.24.0
Pro+

Suggests using context.read() or context.watch() instead of Provider.of(context).

Using context extensions is shorter, helps you keep the codebase consistent and makes it less likely to forget listen: false when read behavior is expected.

Example

❌ Bad:

// LINT: Prefer 'context.watch' instead of 'Provider.of'.
Provider.of(context);

// LINT: Prefer 'context.watch' instead of 'Provider.of'.
Provider.of<String>(context);

// LINT: Prefer 'context.read' instead of 'Provider.of(listen: false)'.
Provider.of<String>(context, listen: false);

✅ Good:

context.watch();
context.read();