Skip to content

Riverpod 2.x.x has no overrideWithValue method

Dart, Flutter, Riverpod1 min read

Today I was upgrading some dependencies in one of my Flutter projects and I decided to see what upgrading Riverpod to 2.0.2 would look like. I was surprised to find that there is no overrideWithValue method anymore.

Where did it go?

I took a look at the CHANGELOG and on GitHub and it looks like overrideWithValue has only been temporarily removed and will re-appear in a subsequent version, I'm just not sure when that might be. It's good to know that it will be coming back eventually, I might just have to hold off on upgrading for now.

This was pretty much the only issue I had with the upgrade from 1.0.3... Which is actually really good compared to some other dependencies I've had to upgrade before in the past. It's a shame because I use this method in a lot of my unit tests to mock values in conjunction with ProviderContainer and the overrides parameter, like this(pseudocode):

1final container = ProviderContainer(overrides: [exampleProvider.overrideWithProvider(ExampleNotifier(isActivated: false))]);

Alternatives? What about overrideWithProvider?

It looks like overrideWithProvider still exists and I could probably figure out a way to use it in my unit tests but I feel like I will end up with a lot of boilerplate code in that case. Maybe there is some way that I can change how things are injected in my providers but again that will end up being a pretty big refactor so I might just wait until a new version with overrideWithValue gets released. Either way I still really appreciate the work put into this great package and it's a still a must for any of my Flutter projects.