Repository: rrousselGit/riverpod

Issue:
Add overrideWith as a replacement to overrideWithProvider
Having to specify the provider type to use `overrideWithProvider` is:
-  tedious for no reason. Having to specify the kind of provider is redundant. 
- Confusing. Some folks believe that the provider created must be global too (to respect the rule of providers).
- Doesn't match with the code-generator, which removes Provider types from the syntax.

Changing the syntax from:

```dart
final futureProvider = FutureProvider.autoDispose<A>((ref) => A());

futureProvider.overrideWithProvider(FutureProvider.autoDispose((ref) => OverrideA()));
```

to:

```dart
final futureProvider = FutureProvider.autoDispose<A>((ref) => A());

futureProvider.overrideWith((ref) => OverrideA());
```

would be a better fit.
Both snippets would have the exact same behavior.

The family variant could also be simplified. Instead of :


```dart
final futureProvider = FutureProvider.autoDispose.family<A, B>((ref, b) => A());

futureProvider.overrideWithProvider((b) => FutureProvider.autoDispose((ref) => OverrideA()));
```


we could have:


```dart
final futureProvider = FutureProvider.autoDispose.family<A, B>((ref, b) => A());

futureProvider.overrideWith((ref, b) => OverrideA());
```







Fix patch:
diff --git a/packages/flutter_riverpod/lib/src/change_notifier_provider/auto_dispose.dart b/packages/flutter_riverpod/lib/src/change_notifier_provider/auto_dispose.dart
index d01e55cb92..27ab252142 100644
--- a/packages/flutter_riverpod/lib/src/change_notifier_provider/auto_dispose.dart
+++ b/packages/flutter_riverpod/lib/src/change_notifier_provider/auto_dispose.dart
@@ -40,6 +40,20 @@ class AutoDisposeChangeNotifierProvider<NotifierT extends ChangeNotifier?>
 
   @override
   late final Refreshable<NotifierT> notifier = _notifier<NotifierT>(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<NotifierT, AutoDisposeChangeNotifierProviderRef<NotifierT>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeChangeNotifierProvider<NotifierT>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [AutoDisposeChangeNotifierProvider].
@@ -70,4 +84,23 @@ class AutoDisposeChangeNotifierProviderFamily<NotifierT extends ChangeNotifier?,
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeChangeNotifierProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    NotifierT Function(
+      AutoDisposeChangeNotifierProviderRef<NotifierT> ref,
+      Arg arg,
+    )
+        create,
+  ) {
+    return FamilyOverrideImpl<NotifierT, Arg,
+        AutoDisposeChangeNotifierProvider<NotifierT>>(
+      this,
+      (arg) => AutoDisposeChangeNotifierProvider<NotifierT>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/flutter_riverpod/lib/src/change_notifier_provider/base.dart b/packages/flutter_riverpod/lib/src/change_notifier_provider/base.dart
index 1079f1be62..9986f5aa8a 100644
--- a/packages/flutter_riverpod/lib/src/change_notifier_provider/base.dart
+++ b/packages/flutter_riverpod/lib/src/change_notifier_provider/base.dart
@@ -110,6 +110,53 @@ class ChangeNotifierProvider<NotifierT extends ChangeNotifier?>
   @override
   late final AlwaysAliveRefreshable<NotifierT> notifier =
       _notifier<NotifierT>(this);
+
+  /// {@template riverpod.overridewith}
+  /// Override the provider with a new initialization function.
+  ///
+  /// This will also disable the auto-scoping mechanism, meaning that if the
+  /// overridden provider specified `dependencies`, it will have no effect.
+  ///
+  /// The override must not specify a `dependencies`.
+  ///
+  /// 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`:
+  ///
+  /// ```dart
+  /// final myService = Provider((ref) => MyService());
+  ///
+  /// runApp(
+  ///   ProviderScope(
+  ///     overrides: [
+  ///       // Replace the implementation of the provider with a different one
+  ///       myService.overrideWithProvider((ref) {
+  ///         ref.watch('other');
+  ///         return MyFakeService(),
+  ///       })),
+  ///     ],
+  ///     child: MyApp(),
+  ///   ),
+  /// );
+  /// ```
+  /// {@endtemplate}
+  Override overrideWith(
+    Create<NotifierT, ChangeNotifierProviderRef<NotifierT>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: ChangeNotifierProvider<NotifierT>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [ChangeNotifierProvider].
@@ -187,4 +234,20 @@ class ChangeNotifierProviderFamily<NotifierT extends ChangeNotifier?, Arg>
     super.name,
     super.dependencies,
   }) : super(providerFactory: ChangeNotifierProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    NotifierT Function(ChangeNotifierProviderRef<NotifierT> ref, Arg arg)
+        create,
+  ) {
+    return FamilyOverrideImpl<NotifierT, Arg,
+        ChangeNotifierProvider<NotifierT>>(
+      this,
+      (arg) => ChangeNotifierProvider<NotifierT>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/CHANGELOG.md b/packages/riverpod/CHANGELOG.md
index 08b02f0e0e..149962c8d6 100644
--- a/packages/riverpod/CHANGELOG.md
+++ b/packages/riverpod/CHANGELOG.md
@@ -1,7 +1,9 @@
 ## [Unreleased minor]
 
-- Deprecate `StateProvider.state`
+- Added `provider.overrideWith((ref) => state`)
+- Deprecated `StateProvider.state`
   Instead, use either `ref.watch(stateProvider)` or `ref.read(stateProvider.notifier).state =`
+- Deprecated `provider.overrideWithProvider`. Instead use `provider.overrideWith`
 - Added `Ref.notifyListeners()` to forcibly notify dependents.
   This can be useful for mutable state.
 - Added `@useResult` to `Ref.refresh`/`WidgetRef.refresh`
diff --git a/packages/riverpod/lib/riverpod.dart b/packages/riverpod/lib/riverpod.dart
index b7cd54ae3b..43e87c9613 100644
--- a/packages/riverpod/lib/riverpod.dart
+++ b/packages/riverpod/lib/riverpod.dart
@@ -24,6 +24,7 @@ export 'src/framework.dart'
         FamilyCreate,
         AsyncSelector,
         FamilyBase,
+        FamilyOverrideImpl,
         AutoDisposeProviderElementMixin,
         FamilyOverride,
         NotifierFamilyBase,
diff --git a/packages/riverpod/lib/src/async_notifier/auto_dispose.dart b/packages/riverpod/lib/src/async_notifier/auto_dispose.dart
index 45f2050e7f..e61dcb0ff7 100644
--- a/packages/riverpod/lib/src/async_notifier/auto_dispose.dart
+++ b/packages/riverpod/lib/src/async_notifier/auto_dispose.dart
@@ -74,6 +74,18 @@ class AutoDisposeAsyncNotifierProviderImpl<
   FutureOr<T> runNotifierBuild(AsyncNotifierBase<T> notifier) {
     return (notifier as AutoDisposeAsyncNotifier<T>).build();
   }
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeAsyncNotifierProviderImpl<NotifierT, T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [AutoDisposeAsyncNotifierProvider].
diff --git a/packages/riverpod/lib/src/async_notifier/auto_dispose_family.dart b/packages/riverpod/lib/src/async_notifier/auto_dispose_family.dart
index 19a49c53c9..1b73542dec 100644
--- a/packages/riverpod/lib/src/async_notifier/auto_dispose_family.dart
+++ b/packages/riverpod/lib/src/async_notifier/auto_dispose_family.dart
@@ -76,4 +76,17 @@ class AutoDisposeAsyncNotifierProviderFamily<
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeFamilyAsyncNotifierProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return FamilyOverrideImpl<AsyncValue<T>, Arg,
+        AutoDisposeFamilyAsyncNotifierProvider<NotifierT, T, Arg>>(
+      this,
+      (arg) => AutoDisposeFamilyAsyncNotifierProvider<NotifierT, T, Arg>(
+        create,
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/async_notifier/base.dart b/packages/riverpod/lib/src/async_notifier/base.dart
index 2b5bdf0d02..e150412a30 100644
--- a/packages/riverpod/lib/src/async_notifier/base.dart
+++ b/packages/riverpod/lib/src/async_notifier/base.dart
@@ -99,6 +99,18 @@ class AsyncNotifierProviderImpl<NotifierT extends AsyncNotifierBase<T>, T>
   FutureOr<T> runNotifierBuild(AsyncNotifierBase<T> notifier) {
     return (notifier as AsyncNotifier<T>).build();
   }
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return ProviderOverride(
+      origin: this,
+      override: AsyncNotifierProviderImpl<NotifierT, T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// A mixin shared by [AsyncNotifierProvider] and [FutureProvider] for dealing with
diff --git a/packages/riverpod/lib/src/async_notifier/family.dart b/packages/riverpod/lib/src/async_notifier/family.dart
index 3acd17072e..1a66c80ce0 100644
--- a/packages/riverpod/lib/src/async_notifier/family.dart
+++ b/packages/riverpod/lib/src/async_notifier/family.dart
@@ -86,4 +86,17 @@ class AsyncNotifierProviderFamily<NotifierT extends FamilyAsyncNotifier<T, Arg>,
     super.name,
     super.dependencies,
   }) : super(providerFactory: AsyncNotifierFamilyProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return FamilyOverrideImpl<AsyncValue<T>, Arg,
+        AsyncNotifierFamilyProvider<NotifierT, T, Arg>>(
+      this,
+      (arg) => AsyncNotifierFamilyProvider<NotifierT, T, Arg>(
+        create,
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/framework/family.dart b/packages/riverpod/lib/src/framework/family.dart
index c3ead78f17..c2c3f79883 100644
--- a/packages/riverpod/lib/src/framework/family.dart
+++ b/packages/riverpod/lib/src/framework/family.dart
@@ -41,7 +41,7 @@ mixin _FamilyMixin<State, Arg, FamilyProvider extends ProviderBase<State>>
   Override overrideWithProvider(
     FamilyProvider Function(Arg argument) override,
   ) {
-    return _FamilyOverride<State, Arg, FamilyProvider>(this, override);
+    return FamilyOverrideImpl<State, Arg, FamilyProvider>(this, override);
   }
 
   @visibleForOverriding
@@ -73,13 +73,18 @@ abstract class FamilyOverride<State> implements Override {
   ProviderBase<State> getProviderOverride(ProviderBase<State> provider);
 }
 
-class _FamilyOverride<State, Arg, FamilyProvider extends ProviderBase<State>>
+/// An [Override] for families
+@internal
+class FamilyOverrideImpl<State, Arg, FamilyProvider extends ProviderBase<State>>
     implements FamilyOverride<State> {
-  _FamilyOverride(this.overriddenFamily, this._newCreate);
+  /// An [Override] for families
+  // ignore: library_private_types_in_public_api
+  FamilyOverrideImpl(this.overriddenFamily, this._newCreate);
 
   final FamilyProvider Function(Arg arg) _newCreate;
 
   @override
+  // ignore: library_private_types_in_public_api
   final _FamilyMixin<State, Arg, FamilyProvider> overriddenFamily;
 
   @visibleForOverriding
diff --git a/packages/riverpod/lib/src/framework/provider_base.dart b/packages/riverpod/lib/src/framework/provider_base.dart
index d126685860..d3bc7a24ce 100644
--- a/packages/riverpod/lib/src/framework/provider_base.dart
+++ b/packages/riverpod/lib/src/framework/provider_base.dart
@@ -249,7 +249,7 @@ mixin OverrideWithValueMixin<State> on ProviderBase<State> {
   }
 }
 
-/// A mixin to add [overrideWithProvider] capability to providers.
+/// A mixin to add `overrideWithProvider` capability to providers.
 extension OverrideWithProviderExtension<State,
     ProviderType extends ProviderBase<State>> on ProviderType {
   /// {@template riverpod.overridewithprovider}
@@ -288,6 +288,7 @@ extension OverrideWithProviderExtension<State,
   /// );
   /// ```
   /// {@endtemplate}
+  @Deprecated('Will be removed in 3.0.0. Use overrideWith instead.')
   Override overrideWithProvider(ProviderType override) {
     assert(
       override.dependencies == null,
diff --git a/packages/riverpod/lib/src/future_provider/auto_dispose.dart b/packages/riverpod/lib/src/future_provider/auto_dispose.dart
index d9424523af..0ee6fd934c 100644
--- a/packages/riverpod/lib/src/future_provider/auto_dispose.dart
+++ b/packages/riverpod/lib/src/future_provider/auto_dispose.dart
@@ -22,7 +22,7 @@ class AutoDisposeFutureProvider<T> extends _FutureProviderBase<T>
   /// {@macro riverpod.family}
   static const family = AutoDisposeFutureProviderFamily.new;
 
-  final FutureOr<T> Function(AutoDisposeFutureProviderRef<T> ref) _createFn;
+  final Create<FutureOr<T>, AutoDisposeFutureProviderRef<T>> _createFn;
 
   @override
   FutureOr<T> _create(AutoDisposeFutureProviderElement<T> ref) =>
@@ -35,6 +35,20 @@ class AutoDisposeFutureProvider<T> extends _FutureProviderBase<T>
 
   @override
   late final Refreshable<Future<T>> future = _future(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<FutureOr<T>, AutoDisposeFutureProviderRef<T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeFutureProvider(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The [ProviderElementBase] of [AutoDisposeFutureProvider]
@@ -60,4 +74,18 @@ class AutoDisposeFutureProviderFamily<R, Arg> extends AutoDisposeFamilyBase<
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeFutureProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    FutureOr<R> Function(AutoDisposeFutureProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<AsyncValue<R>, Arg, AutoDisposeFutureProvider<R>>(
+      this,
+      (arg) => AutoDisposeFutureProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/future_provider/base.dart b/packages/riverpod/lib/src/future_provider/base.dart
index 3a23a1222f..15c2c94cf2 100644
--- a/packages/riverpod/lib/src/future_provider/base.dart
+++ b/packages/riverpod/lib/src/future_provider/base.dart
@@ -33,7 +33,7 @@ class FutureProvider<T> extends _FutureProviderBase<T>
   /// {@macro riverpod.family}
   static const family = FutureProviderFamilyBuilder();
 
-  final FutureOr<T> Function(FutureProviderRef<T> ref) _createFn;
+  final Create<FutureOr<T>, FutureProviderRef<T>> _createFn;
 
   @override
   late final AlwaysAliveRefreshable<Future<T>> future = _future(this);
@@ -43,6 +43,18 @@ class FutureProvider<T> extends _FutureProviderBase<T>
 
   @override
   FutureProviderElement<T> createElement() => FutureProviderElement._(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(Create<FutureOr<T>, FutureProviderRef<T>> create) {
+    return ProviderOverride(
+      origin: this,
+      override: FutureProvider(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of a [FutureProvider]
@@ -82,4 +94,18 @@ class FutureProviderFamily<R, Arg> extends FamilyBase<FutureProviderRef<R>,
     super.name,
     super.dependencies,
   }) : super(providerFactory: FutureProvider<R>.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    FutureOr<R> Function(FutureProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<AsyncValue<R>, Arg, FutureProvider<R>>(
+      this,
+      (arg) => FutureProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/notifier/auto_dispose.dart b/packages/riverpod/lib/src/notifier/auto_dispose.dart
index 8b8753262a..d4b4b75de9 100644
--- a/packages/riverpod/lib/src/notifier/auto_dispose.dart
+++ b/packages/riverpod/lib/src/notifier/auto_dispose.dart
@@ -68,6 +68,18 @@ class AutoDisposeNotifierProviderImpl<NotifierT extends NotifierBase<T>, T>
   T runNotifierBuild(NotifierBase<T> notifier) {
     return (notifier as AutoDisposeNotifier<T>).build();
   }
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeNotifierProviderImpl<NotifierT, T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [AutoDisposeNotifierProvider]
diff --git a/packages/riverpod/lib/src/notifier/auto_dispose_family.dart b/packages/riverpod/lib/src/notifier/auto_dispose_family.dart
index adfb632fc2..bbd59dca76 100644
--- a/packages/riverpod/lib/src/notifier/auto_dispose_family.dart
+++ b/packages/riverpod/lib/src/notifier/auto_dispose_family.dart
@@ -67,4 +67,17 @@ class AutoDisposeNotifierProviderFamily<
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeFamilyNotifierProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return FamilyOverrideImpl<T, Arg,
+        AutoDisposeFamilyNotifierProvider<NotifierT, T, Arg>>(
+      this,
+      (arg) => AutoDisposeFamilyNotifierProvider<NotifierT, T, Arg>(
+        create,
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/notifier/base.dart b/packages/riverpod/lib/src/notifier/base.dart
index 9660bdba80..67e9cac394 100644
--- a/packages/riverpod/lib/src/notifier/base.dart
+++ b/packages/riverpod/lib/src/notifier/base.dart
@@ -129,6 +129,18 @@ class NotifierProviderImpl<NotifierT extends NotifierBase<T>, T>
   T runNotifierBuild(NotifierBase<T> notifier) {
     return (notifier as Notifier<T>).build();
   }
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return ProviderOverride(
+      origin: this,
+      override: NotifierProviderImpl<NotifierT, T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [NotifierProvider].
diff --git a/packages/riverpod/lib/src/notifier/family.dart b/packages/riverpod/lib/src/notifier/family.dart
index 921cbc941a..8f6d08d04a 100644
--- a/packages/riverpod/lib/src/notifier/family.dart
+++ b/packages/riverpod/lib/src/notifier/family.dart
@@ -73,4 +73,17 @@ class NotifierProviderFamily<NotifierT extends FamilyNotifier<T, Arg>, T, Arg>
     super.name,
     super.dependencies,
   }) : super(providerFactory: NotifierFamilyProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWithNotifier(NotifierT Function() create) {
+    return FamilyOverrideImpl<T, Arg,
+        NotifierFamilyProvider<NotifierT, T, Arg>>(
+      this,
+      (arg) => NotifierFamilyProvider<NotifierT, T, Arg>(
+        create,
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/provider/auto_dispose.dart b/packages/riverpod/lib/src/provider/auto_dispose.dart
index 62dea24b29..7b5cb23434 100644
--- a/packages/riverpod/lib/src/provider/auto_dispose.dart
+++ b/packages/riverpod/lib/src/provider/auto_dispose.dart
@@ -28,6 +28,20 @@ class AutoDisposeProvider<T> extends InternalProvider<T> {
   AutoDisposeProviderElement<T> createElement() {
     return AutoDisposeProviderElement._(this);
   }
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<T, AutoDisposeProviderRef<T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeProvider<T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [AutoDisposeProvider]
@@ -48,4 +62,18 @@ class AutoDisposeProviderFamily<R, Arg> extends AutoDisposeFamilyBase<
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    R Function(AutoDisposeProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<R, Arg, AutoDisposeProvider<R>>(
+      this,
+      (arg) => AutoDisposeProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/provider/base.dart b/packages/riverpod/lib/src/provider/base.dart
index 1997f055b3..f94fca684a 100644
--- a/packages/riverpod/lib/src/provider/base.dart
+++ b/packages/riverpod/lib/src/provider/base.dart
@@ -41,6 +41,53 @@ class Provider<State> extends InternalProvider<State>
 
   @override
   ProviderElement<State> createElement() => ProviderElement._(this);
+
+  /// {@template riverpod.overridewith}
+  /// Override the provider with a new initialization function.
+  ///
+  /// This will also disable the auto-scoping mechanism, meaning that if the
+  /// overridden provider specified `dependencies`, it will have no effect.
+  ///
+  /// The override must not specify a `dependencies`.
+  ///
+  /// 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`:
+  ///
+  /// ```dart
+  /// final myService = Provider((ref) => MyService());
+  ///
+  /// runApp(
+  ///   ProviderScope(
+  ///     overrides: [
+  ///       // Replace the implementation of the provider with a different one
+  ///       myService.overrideWithProvider((ref) {
+  ///         ref.watch('other');
+  ///         return MyFakeService(),
+  ///       })),
+  ///     ],
+  ///     child: MyApp(),
+  ///   ),
+  /// );
+  /// ```
+  /// {@endtemplate}
+  Override overrideWith(
+    Create<State, ProviderRef<State>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: Provider<State>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// {@template riverpod.provider}
@@ -286,4 +333,18 @@ class ProviderFamily<R, Arg>
     super.name,
     super.dependencies,
   }) : super(providerFactory: Provider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    R Function(ProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<R, Arg, Provider<R>>(
+      this,
+      (arg) => Provider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/state_notifier_provider/auto_dispose.dart b/packages/riverpod/lib/src/state_notifier_provider/auto_dispose.dart
index 156f170622..1ce56be1b8 100644
--- a/packages/riverpod/lib/src/state_notifier_provider/auto_dispose.dart
+++ b/packages/riverpod/lib/src/state_notifier_provider/auto_dispose.dart
@@ -38,6 +38,20 @@ class AutoDisposeStateNotifierProvider<NotifierT extends StateNotifier<T>, T>
 
   @override
   late final Refreshable<NotifierT> notifier = _notifier(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<NotifierT, AutoDisposeStateNotifierProviderRef<NotifierT, T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeStateNotifierProvider<NotifierT, T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [AutoDisposeStateNotifierProvider].
@@ -67,4 +81,23 @@ class AutoDisposeStateNotifierProviderFamily<NotifierT extends StateNotifier<T>,
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeStateNotifierProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    NotifierT Function(
+      AutoDisposeStateNotifierProviderRef<NotifierT, T> ref,
+      Arg arg,
+    )
+        create,
+  ) {
+    return FamilyOverrideImpl<T, Arg,
+        AutoDisposeStateNotifierProvider<NotifierT, T>>(
+      this,
+      (arg) => AutoDisposeStateNotifierProvider<NotifierT, T>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/state_notifier_provider/base.dart b/packages/riverpod/lib/src/state_notifier_provider/base.dart
index ebfb8ac8d5..f7ea4a213e 100644
--- a/packages/riverpod/lib/src/state_notifier_provider/base.dart
+++ b/packages/riverpod/lib/src/state_notifier_provider/base.dart
@@ -107,6 +107,20 @@ class StateNotifierProvider<NotifierT extends StateNotifier<T>, T>
 
   @override
   late final AlwaysAliveRefreshable<NotifierT> notifier = _notifier(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<NotifierT, StateNotifierProviderRef<NotifierT, T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: StateNotifierProvider<NotifierT, T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [StateNotifierProvider].
@@ -182,4 +196,19 @@ class StateNotifierProviderFamily<NotifierT extends StateNotifier<T>, T, Arg>
     super.name,
     super.dependencies,
   }) : super(providerFactory: StateNotifierProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    NotifierT Function(StateNotifierProviderRef<NotifierT, T> ref, Arg arg)
+        create,
+  ) {
+    return FamilyOverrideImpl<T, Arg, StateNotifierProvider<NotifierT, T>>(
+      this,
+      (arg) => StateNotifierProvider<NotifierT, T>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/state_provider/auto_dispose.dart b/packages/riverpod/lib/src/state_provider/auto_dispose.dart
index a68e180cea..2239b44472 100644
--- a/packages/riverpod/lib/src/state_provider/auto_dispose.dart
+++ b/packages/riverpod/lib/src/state_provider/auto_dispose.dart
@@ -39,6 +39,20 @@ class AutoDisposeStateProvider<T> extends _StateProviderBase<T> {
   )
   @override
   late final Refreshable<StateController<T>> state = _state(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<T, AutoDisposeStateProviderRef<T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeStateProvider<T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [StateProvider].
@@ -59,4 +73,18 @@ class AutoDisposeStateProviderFamily<R, Arg> extends AutoDisposeFamilyBase<
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeStateProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    R Function(AutoDisposeStateProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<R, Arg, AutoDisposeStateProvider<R>>(
+      this,
+      (arg) => AutoDisposeStateProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/state_provider/base.dart b/packages/riverpod/lib/src/state_provider/base.dart
index fdb665fc83..7043e061cf 100644
--- a/packages/riverpod/lib/src/state_provider/base.dart
+++ b/packages/riverpod/lib/src/state_provider/base.dart
@@ -78,6 +78,20 @@ class StateProvider<T> extends _StateProviderBase<T>
   )
   @override
   late final AlwaysAliveRefreshable<StateController<T>> state = _state(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<T, StateProviderRef<T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: StateProvider<T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [StateProvider].
@@ -149,4 +163,18 @@ class StateProviderFamily<R, Arg>
     super.name,
     super.dependencies,
   }) : super(providerFactory: StateProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    R Function(StateProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<R, Arg, StateProvider<R>>(
+      this,
+      (arg) => StateProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/stream_provider/auto_dispose.dart b/packages/riverpod/lib/src/stream_provider/auto_dispose.dart
index c070874df1..28677a7209 100644
--- a/packages/riverpod/lib/src/stream_provider/auto_dispose.dart
+++ b/packages/riverpod/lib/src/stream_provider/auto_dispose.dart
@@ -36,6 +36,20 @@ class AutoDisposeStreamProvider<T> extends _StreamProviderBase<T>
 
   @override
   late final Refreshable<Stream<T>> stream = _stream(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Create<Stream<T>, AutoDisposeStreamProviderRef<T>> create,
+  ) {
+    return ProviderOverride(
+      origin: this,
+      override: AutoDisposeStreamProvider<T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [AutoDisposeStreamProvider].
@@ -61,4 +75,18 @@ class AutoDisposeStreamProviderFamily<R, Arg> extends AutoDisposeFamilyBase<
     super.name,
     super.dependencies,
   }) : super(providerFactory: AutoDisposeStreamProvider.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Stream<R> Function(AutoDisposeStreamProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<AsyncValue<R>, Arg, AutoDisposeStreamProvider<R>>(
+      this,
+      (arg) => AutoDisposeStreamProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }
diff --git a/packages/riverpod/lib/src/stream_provider/base.dart b/packages/riverpod/lib/src/stream_provider/base.dart
index f35eb2719c..976078df15 100644
--- a/packages/riverpod/lib/src/stream_provider/base.dart
+++ b/packages/riverpod/lib/src/stream_provider/base.dart
@@ -102,6 +102,18 @@ class StreamProvider<T> extends _StreamProviderBase<T>
 
   @override
   StreamProviderElement<T> createElement() => StreamProviderElement._(this);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(Create<Stream<T>, StreamProviderRef<T>> create) {
+    return ProviderOverride(
+      origin: this,
+      override: StreamProvider<T>(
+        create,
+        from: from,
+        argument: argument,
+      ),
+    );
+  }
 }
 
 /// The element of [StreamProvider].
@@ -249,4 +261,18 @@ class StreamProviderFamily<R, Arg> extends FamilyBase<StreamProviderRef<R>,
     super.name,
     super.dependencies,
   }) : super(providerFactory: StreamProvider<R>.new);
+
+  /// {@macro riverpod.overridewith}
+  Override overrideWith(
+    Stream<R> Function(StreamProviderRef<R> ref, Arg arg) create,
+  ) {
+    return FamilyOverrideImpl<AsyncValue<R>, Arg, StreamProvider<R>>(
+      this,
+      (arg) => StreamProvider<R>(
+        (ref) => create(ref, arg),
+        from: from,
+        argument: arg,
+      ),
+    );
+  }
 }


Test patch:
diff --git a/packages/flutter_riverpod/test/providers/change_notifier/auto_dispose_change_notifier_provider_test.dart b/packages/flutter_riverpod/test/providers/change_notifier/auto_dispose_change_notifier_provider_test.dart
index 466a1094ef..18ed4e34e7 100644
--- a/packages/flutter_riverpod/test/providers/change_notifier/auto_dispose_change_notifier_provider_test.dart
+++ b/packages/flutter_riverpod/test/providers/change_notifier/auto_dispose_change_notifier_provider_test.dart
@@ -118,6 +118,7 @@ void main() {
         final container = createContainer(
           parent: root,
           overrides: [
+            // ignore: deprecated_member_use
             provider.overrideWithProvider(
               ChangeNotifierProvider.autoDispose((ref) => ValueNotifier(42)),
             ),
diff --git a/packages/flutter_riverpod/test/providers/change_notifier/change_notifier_provider_test.dart b/packages/flutter_riverpod/test/providers/change_notifier/change_notifier_provider_test.dart
index cc54e6cd20..3e9f7986f0 100644
--- a/packages/flutter_riverpod/test/providers/change_notifier/change_notifier_provider_test.dart
+++ b/packages/flutter_riverpod/test/providers/change_notifier/change_notifier_provider_test.dart
@@ -1,4 +1,4 @@
-// ignore_for_file: invalid_use_of_internal_member
+// ignore_for_file: invalid_use_of_internal_member, avoid_types_on_closure_parameters
 
 import 'package:flutter/widgets.dart' hide Listener;
 import 'package:flutter_riverpod/src/internals.dart';
@@ -8,6 +8,58 @@ import 'package:mockito/mockito.dart';
 import '../../utils.dart';
 
 void main() {
+  test('supports overrideWith', () {
+    final provider =
+        ChangeNotifierProvider<ValueNotifier<int>>((ref) => ValueNotifier(0));
+    final autoDispose = ChangeNotifierProvider.autoDispose<ValueNotifier<int>>(
+      (ref) => ValueNotifier(0),
+    );
+
+    final container = createContainer(
+      overrides: [
+        provider.overrideWith(
+          (ChangeNotifierProviderRef<ValueNotifier<int>> ref) =>
+              ValueNotifier(42),
+        ),
+        autoDispose.overrideWith(
+          (AutoDisposeChangeNotifierProviderRef<ValueNotifier<int>> ref) =>
+              ValueNotifier(84),
+        ),
+      ],
+    );
+
+    expect(container.read(provider).value, 42);
+    expect(container.read(autoDispose).value, 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family = ChangeNotifierProvider.family<ValueNotifier<String>, int>(
+      (ref, arg) => ValueNotifier('0 $arg'),
+    );
+    final autoDisposeFamily =
+        ChangeNotifierProvider.autoDispose.family<ValueNotifier<String>, int>(
+      (ref, arg) => ValueNotifier('0 $arg'),
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWith(
+          (ChangeNotifierProviderRef<ValueNotifier<String>> ref, int arg) =>
+              ValueNotifier('42 $arg'),
+        ),
+        autoDisposeFamily.overrideWith(
+          (
+            AutoDisposeChangeNotifierProviderRef<ValueNotifier<String>> ref,
+            int arg,
+          ) =>
+              ValueNotifier('84 $arg'),
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)).value, '42 10');
+    expect(container.read(autoDisposeFamily(10)).value, '84 10');
+  });
+
   test('ref.listenSelf listens to state changes', () {
     final listener = Listener<ValueNotifier<int>>();
     final container = createContainer();
@@ -141,6 +193,7 @@ void main() {
       final container = createContainer(
         parent: root,
         overrides: [
+          // ignore: deprecated_member_use
           provider.overrideWithProvider(
             ChangeNotifierProvider((ref) => ValueNotifier(42)),
           ),
@@ -363,6 +416,7 @@ void main() {
     final notifier2 = TestNotifier();
     final container = createContainer(
       overrides: [
+        // ignore: deprecated_member_use
         provider.overrideWithProvider(ChangeNotifierProvider((_) => notifier)),
       ],
     );
@@ -382,6 +436,7 @@ void main() {
     expect(callCount, 1);
 
     container.updateOverrides([
+      // ignore: deprecated_member_use
       provider.overrideWithProvider(ChangeNotifierProvider((_) => notifier2)),
     ]);
 
diff --git a/packages/riverpod/test/framework/provider_container_test.dart b/packages/riverpod/test/framework/provider_container_test.dart
index 4aab3b0b17..f602e8edb8 100644
--- a/packages/riverpod/test/framework/provider_container_test.dart
+++ b/packages/riverpod/test/framework/provider_container_test.dart
@@ -100,6 +100,7 @@ void main() {
 
       final container = createContainer(
         overrides: [
+          // ignore: deprecated_member_use_from_same_package
           fooProvider.overrideWithProvider(
             Provider<Bar>((ref) => Bar()),
           ),
diff --git a/packages/riverpod/test/framework/scope_test.dart b/packages/riverpod/test/framework/scope_test.dart
index 63e3474830..9532cacb7c 100644
--- a/packages/riverpod/test/framework/scope_test.dart
+++ b/packages/riverpod/test/framework/scope_test.dart
@@ -755,6 +755,7 @@ final b = Provider(
     final a = Provider((ref) => 0);
 
     expect(
+      // ignore: deprecated_member_use_from_same_package
       () => provider.overrideWithProvider(
         Provider((ref) => 0, dependencies: [a]),
       ),
@@ -771,6 +772,7 @@ final b = Provider(
     final root = createContainer(
       overrides: [
         b.overrideWithValue(21),
+        // ignore: deprecated_member_use_from_same_package
         c.overrideWithProvider(Provider((ref) => ref.watch(another) + 10)),
       ],
     );
diff --git a/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart b/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart
index d70334c035..847320014c 100644
--- a/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart
+++ b/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart
@@ -805,6 +805,51 @@ void main() {
     });
   }
 
+  test('supports overrideWithNotifier', () {
+    final provider = AsyncNotifierProvider<AsyncTestNotifier<int>, int>(
+      () => AsyncTestNotifier((ref) => 0),
+    );
+    final autoDispose = AsyncNotifierProvider.autoDispose<
+        AutoDisposeAsyncTestNotifier<int>, int>(
+      () => AutoDisposeAsyncTestNotifier((ref) => 0),
+    );
+    final container = createContainer(
+      overrides: [
+        provider.overrideWithNotifier(() => AsyncTestNotifier((ref) => 42)),
+        autoDispose.overrideWithNotifier(
+          () => AutoDisposeAsyncTestNotifier((ref) => 84),
+        ),
+      ],
+    );
+
+    expect(container.read(provider).value, 42);
+    expect(container.read(autoDispose).value, 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family =
+        AsyncNotifierProvider.family<AsyncTestNotifierFamily<int>, int, int>(
+      () => AsyncTestNotifierFamily<int>((ref) => 0),
+    );
+    final autoDisposeFamily = AsyncNotifierProvider.autoDispose
+        .family<AutoDisposeAsyncTestNotifierFamily<int>, int, int>(
+      () => AutoDisposeAsyncTestNotifierFamily<int>((ref) => 0),
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWithNotifier(
+          () => AsyncTestNotifierFamily<int>((ref) => 42),
+        ),
+        autoDisposeFamily.overrideWithNotifier(
+          () => AutoDisposeAsyncTestNotifierFamily<int>((ref) => 84),
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)).value, 42);
+    expect(container.read(autoDisposeFamily(10)).value, 84);
+  });
+
   group('AutoDispose variant', () {
     test('can watch autoDispose providers', () {
       final dep = Provider.autoDispose((ref) => 0);
diff --git a/packages/riverpod/test/providers/future_provider/auto_dispose_future_provider_test.dart b/packages/riverpod/test/providers/future_provider/auto_dispose_future_provider_test.dart
index c3144bcc67..7a779f78ae 100644
--- a/packages/riverpod/test/providers/future_provider/auto_dispose_future_provider_test.dart
+++ b/packages/riverpod/test/providers/future_provider/auto_dispose_future_provider_test.dart
@@ -249,6 +249,7 @@ void main() {
         parent: root,
         overrides: [
           provider
+              // ignore: deprecated_member_use_from_same_package
               .overrideWithProvider(FutureProvider.autoDispose((ref) => 42)),
         ],
       );
diff --git a/packages/riverpod/test/providers/future_provider/future_provider_test.dart b/packages/riverpod/test/providers/future_provider/future_provider_test.dart
index 2b26686342..4b01ccec5e 100644
--- a/packages/riverpod/test/providers/future_provider/future_provider_test.dart
+++ b/packages/riverpod/test/providers/future_provider/future_provider_test.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: avoid_types_on_closure_parameters
+
 import 'dart:async';
 
 import 'package:mockito/mockito.dart';
@@ -7,6 +9,42 @@ import 'package:test/test.dart';
 import '../../utils.dart';
 
 void main() {
+  test('supports overrideWith', () {
+    final provider = FutureProvider<int>((ref) => 0);
+    final autoDispose = FutureProvider.autoDispose<int>((ref) => 0);
+    final container = createContainer(
+      overrides: [
+        provider.overrideWith((FutureProviderRef<int> ref) => 42),
+        autoDispose.overrideWith(
+          (AutoDisposeFutureProviderRef<int> ref) => 84,
+        ),
+      ],
+    );
+
+    expect(container.read(provider).value, 42);
+    expect(container.read(autoDispose).value, 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family = FutureProvider.family<String, int>((ref, arg) => '0 $arg');
+    final autoDisposeFamily = FutureProvider.autoDispose.family<String, int>(
+      (ref, arg) => '0 $arg',
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWith(
+          (FutureProviderRef<String> ref, int arg) => '42 $arg',
+        ),
+        autoDisposeFamily.overrideWith(
+          (AutoDisposeFutureProviderRef<String> ref, int arg) => '84 $arg',
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)).value, '42 10');
+    expect(container.read(autoDisposeFamily(10)).value, '84 10');
+  });
+
   test('Emits AsyncLoading before the create function is executed', () async {
     final container = createContainer();
     late AsyncValue<int> state;
@@ -329,6 +367,7 @@ void main() {
       final container = createContainer(
         parent: root,
         overrides: [
+          // ignore: deprecated_member_use_from_same_package
           provider.overrideWithProvider(FutureProvider((ref) async => 42)),
         ],
       );
diff --git a/packages/riverpod/test/providers/notifier/notifier_test.dart b/packages/riverpod/test/providers/notifier/notifier_test.dart
index 7321b2df23..4be50758e5 100644
--- a/packages/riverpod/test/providers/notifier/notifier_test.dart
+++ b/packages/riverpod/test/providers/notifier/notifier_test.dart
@@ -350,6 +350,50 @@ void main() {
     }
   }
 
+  test('supports overrideWithNotifier', () {
+    final provider = NotifierProvider<TestNotifier<int>, int>(
+      () => TestNotifier((ref) => 0),
+    );
+    final autoDispose =
+        NotifierProvider.autoDispose<AutoDisposeTestNotifier<int>, int>(
+      () => AutoDisposeTestNotifier((ref) => 0),
+    );
+    final container = createContainer(
+      overrides: [
+        provider.overrideWithNotifier(() => TestNotifier((ref) => 42)),
+        autoDispose.overrideWithNotifier(
+          () => AutoDisposeTestNotifier((ref) => 84),
+        ),
+      ],
+    );
+
+    expect(container.read(provider), 42);
+    expect(container.read(autoDispose), 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family = NotifierProvider.family<TestNotifierFamily<int>, int, int>(
+      () => TestNotifierFamily<int>((ref) => 0),
+    );
+    final autoDisposeFamily = NotifierProvider.autoDispose
+        .family<AutoDisposeTestNotifierFamily<int>, int, int>(
+      () => AutoDisposeTestNotifierFamily<int>((ref) => 0),
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWithNotifier(
+          () => TestNotifierFamily<int>((ref) => 42),
+        ),
+        autoDisposeFamily.overrideWithNotifier(
+          () => AutoDisposeTestNotifierFamily<int>((ref) => 84),
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)), 42);
+    expect(container.read(autoDisposeFamily(10)), 84);
+  });
+
   group('modifiers', () {
     void canBeAssignedToAlwaysAliveRefreshable<T>(
       AlwaysAliveRefreshable<T> provider,
diff --git a/packages/riverpod/test/providers/provider/auto_dispose_provider_test.dart b/packages/riverpod/test/providers/provider/auto_dispose_provider_test.dart
index c73543bd73..c18eaf9424 100644
--- a/packages/riverpod/test/providers/provider/auto_dispose_provider_test.dart
+++ b/packages/riverpod/test/providers/provider/auto_dispose_provider_test.dart
@@ -151,6 +151,7 @@ void main() {
         final container = createContainer(
           parent: root,
           overrides: [
+            // ignore: deprecated_member_use_from_same_package
             provider.overrideWithProvider(Provider.autoDispose((ref) => 42)),
           ],
         );
@@ -170,6 +171,7 @@ void main() {
       });
       final container = createContainer(
         overrides: [
+          // ignore: deprecated_member_use_from_same_package
           provider.overrideWithProvider(override),
         ],
       );
diff --git a/packages/riverpod/test/providers/provider/provider_test.dart b/packages/riverpod/test/providers/provider/provider_test.dart
index 14c77e4456..b1740cddd6 100644
--- a/packages/riverpod/test/providers/provider/provider_test.dart
+++ b/packages/riverpod/test/providers/provider/provider_test.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: avoid_types_on_closure_parameters
+
 import 'package:mockito/mockito.dart';
 import 'package:riverpod/riverpod.dart';
 import 'package:test/test.dart';
@@ -6,6 +8,40 @@ import '../../utils.dart';
 
 void main() {
   group('Provider', () {
+    test('supports overrideWith', () {
+      final provider = Provider<int>((ref) => 0);
+      final autoDispose = Provider.autoDispose<int>((ref) => 0);
+      final container = createContainer(
+        overrides: [
+          provider.overrideWith((ProviderRef<int> ref) => 42),
+          autoDispose.overrideWith(
+            (AutoDisposeProviderRef<int> ref) => 84,
+          ),
+        ],
+      );
+
+      expect(container.read(provider), 42);
+      expect(container.read(autoDispose), 84);
+    });
+
+    test('supports family overrideWith', () {
+      final family = Provider.family<String, int>((ref, arg) => '0 $arg');
+      final autoDisposeFamily = Provider.autoDispose.family<String, int>(
+        (ref, arg) => '0 $arg',
+      );
+      final container = createContainer(
+        overrides: [
+          family.overrideWith((ProviderRef<String> ref, int arg) => '42 $arg'),
+          autoDisposeFamily.overrideWith(
+            (AutoDisposeProviderRef<String> ref, int arg) => '84 $arg',
+          ),
+        ],
+      );
+
+      expect(container.read(family(10)), '42 10');
+      expect(container.read(autoDisposeFamily(10)), '84 10');
+    });
+
     test('can be refreshed', () async {
       var result = 0;
       final container = createContainer();
@@ -167,6 +203,7 @@ void main() {
         final container = createContainer(
           parent: root,
           overrides: [
+            // ignore: deprecated_member_use_from_same_package
             provider.overrideWithProvider(Provider((ref) => 42)),
           ],
         );
diff --git a/packages/riverpod/test/providers/state_notifier_provider/auto_dispose_state_notifier_provider_test.dart b/packages/riverpod/test/providers/state_notifier_provider/auto_dispose_state_notifier_provider_test.dart
index f4ce1a1fe7..3d9ae9c8ac 100644
--- a/packages/riverpod/test/providers/state_notifier_provider/auto_dispose_state_notifier_provider_test.dart
+++ b/packages/riverpod/test/providers/state_notifier_provider/auto_dispose_state_notifier_provider_test.dart
@@ -276,6 +276,7 @@ void main() {
     final notifier2 = TestNotifier(21);
     final container = createContainer(
       overrides: [
+        // ignore: deprecated_member_use_from_same_package
         provider.overrideWithProvider(
           StateNotifierProvider.autoDispose<TestNotifier, int>((_) {
             return notifier;
@@ -297,6 +298,7 @@ void main() {
     verifyOnly(listener, listener(42, 43));
 
     container.updateOverrides([
+      // ignore: deprecated_member_use_from_same_package
       provider.overrideWithProvider(
         StateNotifierProvider.autoDispose<TestNotifier, int>((_) {
           return notifier2;
diff --git a/packages/riverpod/test/providers/state_notifier_provider/state_notifier_provider_test.dart b/packages/riverpod/test/providers/state_notifier_provider/state_notifier_provider_test.dart
index 848150da4a..36be0c4e79 100644
--- a/packages/riverpod/test/providers/state_notifier_provider/state_notifier_provider_test.dart
+++ b/packages/riverpod/test/providers/state_notifier_provider/state_notifier_provider_test.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: avoid_types_on_closure_parameters
+
 import 'package:mockito/mockito.dart';
 import 'package:riverpod/riverpod.dart';
 import 'package:test/test.dart';
@@ -5,6 +7,57 @@ import 'package:test/test.dart';
 import '../../utils.dart';
 
 void main() {
+  test('supports overrideWith', () {
+    final provider = StateNotifierProvider<TestNotifier, int>(
+      (ref) => TestNotifier(),
+    );
+    final autoDispose = StateNotifierProvider.autoDispose<TestNotifier, int>(
+      (ref) => TestNotifier(),
+    );
+    final container = createContainer(
+      overrides: [
+        provider.overrideWith(
+          (StateNotifierProviderRef<TestNotifier, int> ref) => TestNotifier(42),
+        ),
+        autoDispose.overrideWith(
+          (AutoDisposeStateNotifierProviderRef<TestNotifier, int> ref) =>
+              TestNotifier(84),
+        ),
+      ],
+    );
+
+    expect(container.read(provider), 42);
+    expect(container.read(autoDispose), 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family = StateNotifierProvider.family<TestNotifier, int, int>(
+      (ref, arg) => TestNotifier(0 + arg),
+    );
+    final autoDisposeFamily =
+        StateNotifierProvider.autoDispose.family<TestNotifier, int, int>(
+      (ref, arg) => TestNotifier(0 + arg),
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWith(
+          (StateNotifierProviderRef<TestNotifier, int> ref, int arg) =>
+              TestNotifier(42 + arg),
+        ),
+        autoDisposeFamily.overrideWith(
+          (
+            AutoDisposeStateNotifierProviderRef<TestNotifier, int> ref,
+            int arg,
+          ) =>
+              TestNotifier(84 + arg),
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)), 52);
+    expect(container.read(autoDisposeFamily(10)), 94);
+  });
+
   test(
       'on refresh, does not notify listeners if the new value is identical to the previous one',
       () {
@@ -162,6 +215,7 @@ void main() {
         final container = createContainer(
           parent: root,
           overrides: [
+            // ignore: deprecated_member_use_from_same_package
             provider.overrideWithProvider(
               StateNotifierProvider.autoDispose<StateController<int>, int>(
                 (ref) => controllerOverride,
@@ -374,6 +428,7 @@ void main() {
     final notifier2 = TestNotifier(21);
     final container = createContainer(
       overrides: [
+        // ignore: deprecated_member_use_from_same_package
         provider.overrideWithProvider(
           StateNotifierProvider<TestNotifier, int>((_) {
             return notifier;
@@ -396,6 +451,7 @@ void main() {
     verifyOnly(listener, listener(42, 43));
 
     container.updateOverrides([
+      // ignore: deprecated_member_use_from_same_package
       provider.overrideWithProvider(
         StateNotifierProvider<TestNotifier, int>((_) {
           return notifier2;
diff --git a/packages/riverpod/test/providers/state_provider/state_provider_auto_dispose_test.dart b/packages/riverpod/test/providers/state_provider/state_provider_auto_dispose_test.dart
index 499658000d..bea620cdb4 100644
--- a/packages/riverpod/test/providers/state_provider/state_provider_auto_dispose_test.dart
+++ b/packages/riverpod/test/providers/state_provider/state_provider_auto_dispose_test.dart
@@ -178,6 +178,7 @@ void main() {
       final container = createContainer(
         parent: root,
         overrides: [
+          // ignore: deprecated_member_use_from_same_package
           provider.overrideWithProvider(
             StateProvider.autoDispose((ref) => 42, name: 'meh'),
           ),
diff --git a/packages/riverpod/test/providers/state_provider/state_provider_test.dart b/packages/riverpod/test/providers/state_provider/state_provider_test.dart
index d7319672f4..a82b4e225a 100644
--- a/packages/riverpod/test/providers/state_provider/state_provider_test.dart
+++ b/packages/riverpod/test/providers/state_provider/state_provider_test.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: avoid_types_on_closure_parameters
+
 import 'package:mockito/mockito.dart';
 import 'package:riverpod/riverpod.dart';
 import 'package:test/test.dart';
@@ -5,6 +7,44 @@ import 'package:test/test.dart';
 import '../../utils.dart';
 
 void main() {
+  test('supports overrideWith', () {
+    final provider = StateProvider<int>(
+      (ref) => 0,
+    );
+    final autoDispose = StateProvider.autoDispose<int>(
+      (ref) => 0,
+    );
+    final container = createContainer(
+      overrides: [
+        provider.overrideWith((StateProviderRef<int> ref) => 42),
+        autoDispose.overrideWith((AutoDisposeStateProviderRef<int> ref) => 84),
+      ],
+    );
+
+    expect(container.read(provider), 42);
+    expect(container.read(autoDispose), 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family = StateProvider.family<String, int>((ref, arg) => '0 $arg');
+    final autoDisposeFamily = StateProvider.autoDispose.family<String, int>(
+      (ref, arg) => '0 $arg',
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWith(
+          (StateProviderRef<String> ref, int arg) => '42 $arg',
+        ),
+        autoDisposeFamily.overrideWith(
+          (AutoDisposeStateProviderRef<String> ref, int arg) => '84 $arg',
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)), '42 10');
+    expect(container.read(autoDisposeFamily(10)), '84 10');
+  });
+
   test(
       'on refresh, does not notify listeners if the new value is identical to the previous one',
       () {
@@ -250,6 +290,7 @@ void main() {
       final container = createContainer(
         parent: root,
         overrides: [
+          // ignore: deprecated_member_use_from_same_package
           provider.overrideWithProvider(
             StateProvider((ref) => 42),
           ),
diff --git a/packages/riverpod/test/providers/stream_provider/auto_dispose_stream_provider_test.dart b/packages/riverpod/test/providers/stream_provider/auto_dispose_stream_provider_test.dart
index d8fdb1df3d..8919c76c94 100644
--- a/packages/riverpod/test/providers/stream_provider/auto_dispose_stream_provider_test.dart
+++ b/packages/riverpod/test/providers/stream_provider/auto_dispose_stream_provider_test.dart
@@ -253,6 +253,7 @@ void main() {
         final container = createContainer(
           parent: root,
           overrides: [
+            // ignore: deprecated_member_use_from_same_package
             provider.overrideWithProvider(
               StreamProvider.autoDispose((ref) => Stream.value(42)),
             ),
diff --git a/packages/riverpod/test/providers/stream_provider/stream_provider_test.dart b/packages/riverpod/test/providers/stream_provider/stream_provider_test.dart
index 0f5aa4d226..4acbd67098 100644
--- a/packages/riverpod/test/providers/stream_provider/stream_provider_test.dart
+++ b/packages/riverpod/test/providers/stream_provider/stream_provider_test.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: avoid_types_on_closure_parameters
+
 import 'dart:async';
 
 import 'package:mockito/mockito.dart';
@@ -21,6 +23,68 @@ void main() {
     controller.close();
   });
 
+  test('supports overrideWith', () {
+    final provider = StreamProvider<int>(
+      (ref) {
+        ref.state = const AsyncData(0);
+        return Stream.value(1);
+      },
+    );
+    final autoDispose = StreamProvider.autoDispose<int>(
+      (ref) {
+        ref.state = const AsyncData(0);
+        return Stream.value(1);
+      },
+    );
+    final container = createContainer(
+      overrides: [
+        provider.overrideWith((StreamProviderRef<int> ref) {
+          ref.state = const AsyncData(42);
+          return Stream.value(43);
+        }),
+        autoDispose.overrideWith((AutoDisposeStreamProviderRef<int> ref) {
+          ref.state = const AsyncData(84);
+          return Stream.value(85);
+        }),
+      ],
+    );
+
+    expect(container.read(provider).value, 42);
+    expect(container.read(autoDispose).value, 84);
+  });
+
+  test('supports family overrideWith', () {
+    final family = StreamProvider.family<String, int>((ref, arg) {
+      ref.state = AsyncData('0 $arg');
+      return Stream.value('1 $arg');
+    });
+    final autoDisposeFamily = StreamProvider.autoDispose.family<String, int>(
+      (ref, arg) {
+        ref.state = AsyncData('0 $arg');
+        return Stream.value('1 $arg');
+      },
+    );
+    final container = createContainer(
+      overrides: [
+        family.overrideWith(
+          (StreamProviderRef<String> ref, int arg) {
+            ref.state = AsyncData('42 $arg');
+            return Stream.value('43 $arg');
+          },
+        ),
+        autoDisposeFamily.overrideWith(
+          (AutoDisposeStreamProviderRef<String> ref, int arg) {
+            ref.state = AsyncData('84 $arg');
+            return Stream.value('85 $arg');
+          },
+        ),
+      ],
+    );
+
+    expect(container.read(family(10)).value, '42 10');
+    expect(container.read(autoDisposeFamily(10)).value, '84 10');
+  });
+
   test('Emits AsyncLoading before the create function is executed', () async {
     final container = createContainer();
     late AsyncValue<int> state;
@@ -286,6 +350,7 @@ void main() {
         parent: root,
         overrides: [
           provider
+              // ignore: deprecated_member_use_from_same_package
               .overrideWithProvider(StreamProvider((ref) => Stream.value(42))),
         ],
       );
@@ -621,7 +686,7 @@ void main() {
 
     // No value were emitted, so the future will fail. Catching the error to
     // avoid false positive.
-    // ignore: unawaited_futures, avoid_types_on_closure_parameters
+    // ignore: unawaited_futures
     container.read(provider.future).catchError((Object _) => 0);
   });