Replies: 1 comment 1 reply
-
You can just call your api in your buttons and then call 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 CarManager {
final Ref _ref;
const CarManager(this._ref);
Future<void> updatePlate(car, plate) async {
await _ref.read(apiProvider).updatePlate(car, plate);
if (_ref.exists(listProvider)) {
_ref.read(listProvider.notifier).updatePlate(car, plate);
}
if (_ref.exists(detailProvider)) {
_ref.read(detailProvider.notifier).updatePlate(car, plate);
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there 👋
TLDR; I have a list and a detail provider of the "same" entity holding some shared state, when updating that shared state who is resposible for the API Call?
I am developing an Fleet and Warehouse Management System in Flutter using Riverpod and Supabase.
Currently I am stuck on how to manage the following problem:
In my database I have the following entities:
Cars - Which store information about the car like plate, manufacturer etc.
CarReservations - Which store information about a cars reservation like start and end date etc.
I want to display an overview about the current fleet in my flutter app and thus created a database view called current_fleet which aggregates all cars and checks if there is any existing car reservation where the current time is in the reservation ("there is an active reservation at this given time"). To prevent overfetching this table only has some data about the car but not all.
Since there is also a detail view of each car, which contains more information about a car, I have a CarDetailsProvider which fetches all the information about the car to display it.
I now want the user to be able to update the e.g. plate from either the detail view or the overview.
Now to my questions:
How can I keep both providers in sync when updating the car?
My only guess is to make both providers a notifier and implement an "updatePlate" method on both but who should be responsible for the API call? The "List"-Provider or the "Detail"-Provider? Is there any best practice?
Beta Was this translation helpful? Give feedback.
All reactions