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
Display Dialog or SnackBar from Action's before method #21
Comments
@jans-y I am personally trying to remove any reference to Instead, I am leveraging For example: @override
void didUpdateWidget(MyWidget oldWidget) {
super.didUpdateWidget(oldWidget);
consumeEvents(context);
}
void consumeEvents(BuildContext context) {
if (widget.showDialogEvt.consume()) { // code to showDialog here }
} So you can have a |
@gadfly361 is right. Usually Events are the way to go when you need to display dialogs. Why? Actions belong to the "business layer", and they should not know about Flutter widgets, let alone contexts, which are in the "client/UI layer". So you should use an Event to signal to some widget that it needs to open a dialog. Just to complement Matthew's answer:
One of your widgets should be listening to However, if all you want is a dialog with some text that displays an error message, then there is no need to do any of that. You can just throw an UserException:
This UserException will be caught by AsyncRedux, which will display a dialog with the message. For more details on how to setup AsyncRedux to display these dialogs, see this: https://pub.dev/packages/async_redux#user-exceptions |
Thank you for your guidance. This library is evolving so rapidly that I have must missed the UserException. It works ok, but I will probably end up building my own "UserException" class which will show Cupertino dialog on iOS and possibly a SnackBar. |
@jans-y That surely is a good idea of improving the UserExceptionDialog class. Please share your implementation here if you can. Thanks. |
Hi, I forked it locally and did this:
|
@jans-y Added this to version 2.3.3. |
Hi, Thank you for adding the code I proposed before. I have started to experiment with Flutter for web and found out that it has to be update to not break web compilation: ➕add import Change condition 📱 I would create PR but I never did it on GitHub on someone's others project. Thank you. |
Done: version 2.4.3. |
Hi,
I really enjoy using your library. It makes it so much easier to use the Redux with Flutter. Thank you.
I would like to ask how can I get a correct context to be able to display Dialog or SnackBar from the before method inside an abstract class.
I was hoping something like navigatorKey.currentState.context would work but I wasn't successful.
I have also tried passing current context to the Action itself ->
store.dispatch(SomeAction(context))
but I don't know how to pass it into the before method without overriding it, which adds (maybe) unnecessary complexity.Thank you for your advice.
The text was updated successfully, but these errors were encountered: