Skip to content

Commit dbea8ec

Browse files
committed
dialog: Support suggested-action dialog with title only, no message
1 parent da3577b commit dbea8ec

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/widgets/dialog.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ DialogStatus<void> showErrorDialog({
145145
DialogStatus<bool> showSuggestedActionDialog({
146146
required BuildContext context,
147147
required String title,
148-
required String message,
148+
String? message,
149149
required String? actionButtonText,
150150
bool destructiveActionButton = false,
151151
}) {
@@ -154,7 +154,7 @@ DialogStatus<bool> showSuggestedActionDialog({
154154
context: context,
155155
builder: (BuildContext context) => AlertDialog.adaptive(
156156
title: Text(title),
157-
content: _adaptiveContent(Text(message)),
157+
content: message != null ? _adaptiveContent(Text(message)) : null,
158158
actions: [
159159
_adaptiveAction(
160160
onPressed: () => Navigator.pop<bool>(context, null),

test/widgets/dialog_checks.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void checkNoDialog(WidgetTester tester) {
109109
/// Tap the action button by calling `tester.tap(find.byWidget(actionButton))`.
110110
(Widget, Widget) checkSuggestedActionDialog(WidgetTester tester, {
111111
required String expectedTitle,
112-
required String expectedMessage,
112+
String? expectedMessage,
113113
String? expectedActionButtonText,
114114
bool expectDestructiveActionButton = false,
115115
}) {
@@ -121,8 +121,10 @@ void checkNoDialog(WidgetTester tester) {
121121
final dialog = tester.widget<AlertDialog>(find.bySubtype<AlertDialog>());
122122
tester.widget(find.descendant(matchRoot: true,
123123
of: find.byWidget(dialog.title!), matching: find.text(expectedTitle)));
124-
tester.widget(find.descendant(matchRoot: true,
125-
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
124+
if (expectedMessage != null) {
125+
tester.widget(find.descendant(matchRoot: true,
126+
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
127+
}
126128

127129
final actionButton = tester.widget(find.descendant(of: find.byWidget(dialog),
128130
matching: find.widgetWithText(TextButton, expectedActionButtonText ?? 'Continue')));
@@ -135,8 +137,10 @@ void checkNoDialog(WidgetTester tester) {
135137
final dialog = tester.widget<CupertinoAlertDialog>(find.byType(CupertinoAlertDialog));
136138
tester.widget(find.descendant(matchRoot: true,
137139
of: find.byWidget(dialog.title!), matching: find.text(expectedTitle)));
138-
tester.widget(find.descendant(matchRoot: true,
139-
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
140+
if (expectedMessage != null) {
141+
tester.widget(find.descendant(matchRoot: true,
142+
of: find.byWidget(dialog.content!), matching: find.text(expectedMessage)));
143+
}
140144

141145
final actionButton = tester.widget<CupertinoDialogAction>(
142146
find.descendant(

0 commit comments

Comments
 (0)