Skip to content

Commit c5f4e93

Browse files
committed
dialog [nfc]: Simplify new showErrorDialog interface a bit
Unlike ScaffoldFeatureController which inspired it, this class doesn't offer a way to control the dialog, so it's not really a "controller"; just call it DialogStatus. A private final field with a public getter (of the same type) is equivalent to just a public final field: nothing can set it, and any library can get it. Also generalize the description a bit: we currently use this only for AlertDialog, but it'd apply equally well for any dialog box.
1 parent 17fa38c commit c5f4e93

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

lib/widgets/content.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ class GlobalTime extends StatelessWidget {
11951195
}
11961196

11971197
void _launchUrl(BuildContext context, String urlString) async {
1198-
DialogStatusController showError(BuildContext context, String? message) {
1198+
DialogStatus showError(BuildContext context, String? message) {
11991199
return showErrorDialog(context: context,
12001200
title: 'Unable to open link',
12011201
message: [

lib/widgets/dialog.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@ Widget _dialogActionText(String text) {
1515
);
1616
}
1717

18-
/// A wrapper providing access to the status of an [AlertDialog].
18+
/// Tracks the status of a dialog, in being still open or already closed.
1919
///
2020
/// See also:
2121
/// * [showDialog], whose return value this class is intended to wrap.
22-
class DialogStatusController {
23-
const DialogStatusController(this._closed);
22+
class DialogStatus {
23+
const DialogStatus(this.closed);
2424

2525
/// Resolves when the dialog is closed.
26-
Future<void> get closed => _closed;
27-
final Future<void> _closed;
26+
final Future<void> closed;
2827
}
2928

3029
/// Displays an [AlertDialog] with a dismiss button.
3130
///
32-
/// Returns a [DialogStatusController]. Useful for checking if the dialog has
33-
/// been closed.
31+
/// The [DialogStatus.closed] field of the return value can be used
32+
/// for waiting for the dialog to be closed.
3433
// This API is inspired by [ScaffoldManager.showSnackBar]. We wrap
35-
// [showDialog]'s return value, a [Future], inside [DialogStatusController]
34+
// [showDialog]'s return value, a [Future], inside [DialogStatus]
3635
// whose documentation can be accessed. This helps avoid confusion when
3736
// intepreting the meaning of the [Future].
38-
DialogStatusController showErrorDialog({
37+
DialogStatus showErrorDialog({
3938
required BuildContext context,
4039
required String title,
4140
String? message,
@@ -51,7 +50,7 @@ DialogStatusController showErrorDialog({
5150
onPressed: () => Navigator.pop(context),
5251
child: _dialogActionText(zulipLocalizations.errorDialogContinue)),
5352
]));
54-
return DialogStatusController(future);
53+
return DialogStatus(future);
5554
}
5655

5756
void showSuggestedActionDialog({

0 commit comments

Comments
 (0)