Skip to content

Commit c4ec916

Browse files
gnpricePIG208
authored andcommitted
wip reportErrorToUserBriefly; TODO doc, test
1 parent ff239dd commit c4ec916

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/log.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ bool debugLog(String message) {
3030
}());
3131
return true;
3232
}
33+
34+
void Function(String message) reportErrorToUserBriefly = _defaultReportErrorToUserBriefly;
35+
36+
void _defaultReportErrorToUserBriefly(String message) {
37+
// If this callback is still in place, then the app's widget tree
38+
// hasn't mounted yet even as far as the [Navigator].
39+
// So there's not much we can do to tell the user;
40+
// just log, in case the user is actually a developer watching the console.
41+
assert(debugLog(message));
42+
}

lib/widgets/app.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
55
import 'package:flutter/scheduler.dart';
66
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
77

8+
import '../log.dart';
89
import '../model/localizations.dart';
910
import '../model/narrow.dart';
1011
import 'about_zulip.dart';
@@ -92,9 +93,14 @@ class ZulipApp extends StatefulWidget {
9293
/// Useful in tests.
9394
final List<NavigatorObserver>? navigatorObservers;
9495

96+
static void _reportErrorToUserBriefly(String message) {
97+
scaffoldMessenger?.showSnackBar(SnackBar(content: Text(message)));
98+
}
99+
95100
void _declareReady() {
96101
assert(navigatorKey.currentContext != null);
97102
_ready.value = true;
103+
reportErrorToUserBriefly = _reportErrorToUserBriefly;
98104
}
99105

100106
@override

0 commit comments

Comments
 (0)