overrideWithValue method

Override overrideWithValue(
  1. Notifier value

Overrides a provider with a value, ejecting the default behaviour.

This will also disable the auto-scoping mechanism, meaning that if the overridden provider specified dependencies, it will have no effect.

Some common use-cases are:

  • testing, by replacing a service with a fake implementation, or to reach a very specific state easily.
  • multiple environments, by changing the implementation of a class based on the platform or other parameters.

This function should be used in combination with ProviderScope.overrides or ProviderContainer.overrides:

final myService = Provider((ref) => MyService());

    overrides: [
        // Replace the implementation of MyService with a fake implementation
    child: MyApp(),


Override overrideWithValue(Notifier value) {
  return ProviderOverride(
    origin: notifier,
    override: ValueProvider<Notifier>(value),