Skip to content

Commit 5df50b7

Browse files
committed
log: Return Future from reportErrorToUserBriefly.
Similar to the refactor in commit ece8f72 to `showErrorDialog`, returning `Future` here allows the caller to know when the `SnackBar` is closed. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 96f551e commit 5df50b7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/log.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool debugLog(String message) {
3131
return true;
3232
}
3333

34-
typedef ReportErrorCallback = void Function(String? message, {String? details});
34+
typedef ReportErrorCallback = Future<void> Function(String? message, {String? details});
3535

3636
/// Display an error message in a [SnackBar].
3737
///
@@ -43,12 +43,15 @@ typedef ReportErrorCallback = void Function(String? message, {String? details});
4343
///
4444
/// If `details` is non-null, the [SnackBar] will contain a button that would
4545
/// open a dialog containing the error details.
46+
///
47+
/// Returns a [Future] that resolves when the [SnackBar] is no longer visible.
48+
/// If [ZulipApp] is not ready, the [Future] resolves immediately.
4649
// This gets set in [ZulipApp]. We need this indirection to keep `lib/log.dart`
4750
// from importing widget code, because the file is a dependency for the rest of
4851
// the app.
4952
ReportErrorCallback reportErrorToUserBriefly = defaultReportErrorToUserBriefly;
5053

51-
void defaultReportErrorToUserBriefly(String? message, {String? details}) {
54+
Future<void> defaultReportErrorToUserBriefly(String? message, {String? details}) async {
5255
// Error dismissing is a no-op to the default handler.
5356
if (message == null) return;
5457
// If this callback is still in place, then the app's widget tree

lib/widgets/app.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ZulipApp extends StatefulWidget {
9898

9999
static int _snackBarCount = 0;
100100

101-
static void _reportErrorToUserBriefly(String? message, {String? details}) {
101+
static Future<void> _reportErrorToUserBriefly(String? message, {String? details}) async {
102102
assert(_ready.value);
103103

104104
if (message == null) {
@@ -129,7 +129,8 @@ class ZulipApp extends StatefulWidget {
129129
message: details))));
130130

131131
_snackBarCount++;
132-
newSnackBar.closed.whenComplete(() => _snackBarCount--);
132+
await newSnackBar.closed;
133+
_snackBarCount--;
133134
}
134135

135136
void _declareReady() {

0 commit comments

Comments
 (0)