Skip to content

Syncing providers managing the "same" entity #3712

Answered by gdurandrexel
w0rsti asked this question in Q&A
Discussion options

You must be logged in to vote

You can just call your api in your buttons and then call ref.invalidate(listProvider) and same for detailProvider.
But it's costly as the providers will be rebuilt. You can instead have an updatePlate() method in both providers, in which you update the provider state directly. You should probably check if ref.exists(provider) before trying to call these methods.

In any case, where you place the update API call is not really important regarding riverpod I guess.

You can also have class CarManager where you put your update methods, which perform the update API call and then the provider updates.

@Riverpod(keepAlive: true)
CarManager carManager(CarManagerRef ref) => CarManager(ref);

class C…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@w0rsti
Comment options

Answer selected by w0rsti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants