Skip to main content

prefer-immutable-provider-arguments

effort: 3m
starter+

Warns when a Provider's argument does not have a consistent ==.

Example

❌ Bad:

// LINT: Avoid passing arguments without consistent '=='.
// Try passing a primitive, constant or immutable object that overrides '==' and 'hashCode'.
ref.watch(someProvider(SomeClassWithoutEquals()));

// LINT: Avoid passing arguments without consistent '=='.
// Try passing a primitive, constant or immutable object that overrides '==' and 'hashCode'.
ref.watch(someProvider([42]));

// LINT: Avoid passing arguments without consistent '=='.
// Try passing a primitive, constant or immutable object that overrides '==' and 'hashCode'.
ref.watch(someProvider(() { ... }));

✅ Good:

ref.watch(someProvider(SomeClassWithEquals()));
ref.watch(someProvider(const SomeClass()));
ref.watch(someProvider(const Object()));
ref.watch(someProvider(const [42]));
ref.watch(someProvider(const {'string': 42}));
ref.watch(someProvider(variable));