-
Notifications
You must be signed in to change notification settings - Fork 309
lightbox: Replace onDismiss with await showErrorDialog
#937
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
Conversation
7d18cfa
to
0bae716
Compare
LGTM assuming you've tested this manually; marking for Greg's review. |
I forgot to mention that this shouldn't be an nfc change, because the user can close the dialog by tapping the barrier now. Pushed an update to the commit message to reflect that. |
0bae716
to
b088e39
Compare
Makes sense. Ah and I think |
f27b62c
to
1df1035
Compare
The `showDialog` function returns a future that resolves when the dialog is dismissed, and showErrorDialog returns that future. The one caller of showErrorDialog that was passing an onDismiss callback can therefore await that future instead. Do that, and eliminate the parameter. This is not an NFC change, because now the user can tap the barrier (the darkened area around the dialog) to close it. Discussion from when this parameter was introduced: zulip#587 (comment) Signed-off-by: Zixuan James Li <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is a nice cleanup.
Merging, with a revision to the commit message:
lightbox: Replace onDismiss with `await showErrorDialog`
- `showDialog` returns a `Future` that resolves when the dialog is
- dismissed.
+ The `showDialog` function returns a future that resolves when the
+ dialog is dismissed, and showErrorDialog returns that future.
- This refactors `showErrorDialog` to stop overriding `onPressed` and
- `barrierDismissible`, and make the caller call `Navigator.pop` one
- more time once the dialog is closed.
+ The one caller of showErrorDialog that was passing an onDismiss
+ callback can therefore await that future instead. Do that, and
+ eliminate the parameter.
- This is not an nfc because now the user can tap the barrier (darkened
- area around the dialog) to close it.
+ This is not an NFC change, because now the user can tap the barrier
+ (the darkened area around the dialog) to close it.
- Note that we check for `mounted` again because there has been an
- asynchronous gap.
-
- See also:
+ Discussion from when this parameter was introduced:
https://github.com/zulip/zulip-flutter/pull/587#discussion_r1585845428
The main change is to explain more of the "why", and delete several details of "what" which the reader can more easily learn by looking at the diff.
/// Returns a [Future] that resolves when the dialog is closed. | ||
Future<void> showErrorDialog({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior (which showDialog
has and we faithfully wrap) is kind of a bad pattern for an API, as we've discussed in the context of #731 / the unawaited_futures
lint. If a function is named "show thing" and its return type is some Future<T>
, the future should complete when the thing has been shown, not when some possibly-much-later event happens.
I think a good model here is ScaffoldMessengerState.showSnackBar
: there's a Future it wants to provide for callers to potentially await on, but it's for something that happens after the function's own work is done, so instead of returning a value that is a Future it returns a value that has a Future. And the property name, closed
, makes it clear what event is being awaited.
Anyway, that's a problem for outside this PR.
1df1035
to
12f39ea
Compare
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
As a result, showErrorDialog no longer returns a Future that can be mistakenly awaited. The wrapped return value offers clarity on how the Future is supposed to be used. There is no user visible change because existing callers (other than lightbox's) that wait for its return value are all asynchronous handlers for UI elements like buttons, and waits unnecessarily. See also discussion zulip#937 (comment). Signed-off-by: Zixuan James Li <[email protected]>
showDialog
returns aFuture
that resolves when the dialog is dismissed.This refactors
showErrorDialog
to stop overridingonPressed
andbarrierIsDismissable
, and make the caller call Navigator.pop one more time once the dialog is closed.Note that we check for
mounted
again because there has been an asynchronous gap.See also:
#587 (comment)