website/docs/concepts2/overrides.mdx
import { Link } from "/src/components/Link"; import { AutoSnippet, } from "/src/components/CodeSnippet"; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
In Riverpod, all providers can be overridden to change their behavior. This is useful for testing, debugging, or providing different implementations in different environments, or even <Link documentID="concepts2/scoping"/>.
Overriding a provider is done on <Link documentID="concepts2/containers"/>, using the overrides parameter.
In it, you can specify a list of instructions on how to override a specific provider.
Such "instruction" is created using your provider, combined with value methods named overrideWithSomething.
There are a bunch of these methods available, but all of them have their name starting with overrideWith.
This includes:
A typical override looks like this:
<Tabs> <TabItem value="scope" label="ProviderScope">void main() {
runApp(
ProviderScope(
overrides: [
// Your overrides are defined here.
// The following shows how to override a "counter provider"
// to use a different initial value.
counterProvider.overrideWith((ref) => 42),
]
)
);
}
final container = ProviderContainer(
overrides: [
// Your overrides are defined here.
// The following shows how to override a "counter provider"
// to use a different initial value.
counterProvider.overrideWith((ref) => 42),
]
);