-
-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What should I do to pass events from provider to view? #21
Comments
Could you expand on this? I don't understand the question. |
In a real world example, when the user clicks the login button, I will call the login (username, password) function of the provider. and provider after processing will display the result of success or failure, View will display a dialog message to the user. But in this case, the provider cannot directly display the dialog message. |
It is not the role of providers to display dialogs. Make your provider return the result, and have the UI process that result to display things |
I think if you do that, the view will have to handle a bit of logic. As with MVP architecture, View will only provide an interface to the presenter and the View will not implement any logic. |
Showing a modal is not business logic but UI logic. |
in some special cases, an intermittent process and it needs to show the message while it has not finished running. For example, the process of loading my data consists of 5 parts, and after the download is complete, each part will display a message and continue to download the next part, if processed in View, there will need 5 separate functions or At least logic view will have to call at 5 times.
|
It would be simpler to write like this:
|
Maybe expose a Stream and have the UI listen to it to call |
but how can I listen stream (for user not use hook)?
|
stream.listen(...) or StreamBuilder |
Can you write a simple example about listen stream from View ? |
myProvider.read(context).myStream.listen(...) |
But it throw Exception when use in build. |
You need a StatefulWidget for this, or hooks. You cannot listen to an object inside StatelessWidgets. |
I think it is a best option for now. |
What should I do to pass events from provider to view? For example from the provider I want to pass an event that displays a dialog or a snackbar.
The text was updated successfully, but these errors were encountered: