Skip to main content

prefer-nullable-provider-types

effort: 2m
teams+

Warns when a specified type of the context.watch, context.read or Provider.of is non-nullable.

note

Use this rule if you rely on conditionally provided values and are dealing with not handled missing value cases.

Example

❌ Bad:

// LINT: Prefer nullable provider types to always handle cases when the provided value is not available.
final value = context.watch<String>();

// LINT: Prefer nullable provider types to always handle cases when the provided value is not available.
final anotherValue = context.read<int>();

// LINT: Prefer nullable provider types to always handle cases when the provided value is not available.
Provider.of<String>(context);

✅ Good:

final value = context.watch<String?>();
final anotherValue = context.read<int?>();
Provider.of<String?>(context);