Overriding build of a provider at runtime #4256
Unanswered
bbhawal-atec
asked this question in
Q&A
Replies: 1 comment
-
Well, you can do this if you create a Notifier for the getUserProvider. class UserProvider extends Notifier<String> {
@override
String build() {
// do nothing
return "";
}
Future<void> request() async {
// network call
}
void overrideUser(String model) {
state = model;
}
} This would mean, that you never automatically do a network call which is probably not in your favor. A better solution would be, to store your results of You could swap out the "from disk" part with a static cache if you only want this to be in memory. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not sure if this is possible; however, I am trying to create a workflow with two providers,
getAllUsersProvider
andgetUserProvider
and they are setup to have cache for 1 minutes..The
getAllUsersProvider(int page)
allows us to get a paginated list of users by making an async call.The
getUserProvider(String id)
allows us to get a single user by malking an async call.When we call
getAllUsersProvider
I want to loadgetUserProvider
for each user in the list however instead of making the api call I want to be able to pass in the user model.However, if I were to call getUserProvider and not getAllUserProvider then I want it make the API call.
By doing this it allows us to optimise the number of requests being made since we already got the data from the
getAllUsersProvider
Would this be possilbe.
Beta Was this translation helpful? Give feedback.
All reactions