Skip to content

Commit be39701

Browse files
committed
feat: specify the expected return type when showing dialogs
1 parent 578b3f4 commit be39701

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/src/platform/dialog_helper.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,30 @@ class DialogHelper {
8383
/// Shows a simple text dialog with the given [title] and [text].
8484
///
8585
/// Compare [showWidgetDialog] for parameter details.
86-
static Future showTextDialog(
86+
static Future<T?> showTextDialog<T>(
8787
BuildContext context,
8888
String title,
8989
String text, {
9090
List<Widget>? actions,
9191
String? okActionText,
9292
String? cancelActionText,
93-
}) {
94-
return showWidgetDialog(context, Text(text),
93+
}) =>
94+
showWidgetDialog<T>(
95+
context,
96+
Text(text),
9597
title: title,
9698
actions: actions,
9799
okActionText: okActionText,
98-
cancelActionText: cancelActionText);
99-
}
100+
cancelActionText: cancelActionText,
101+
);
100102

101103
/// Shows a dialog with the given [content].
102104
///
103105
/// Set the [title] to display the title on top
104106
/// Specify custom [actions] to provide dialog specific actions, alternatively specify the [defaultActions]. Without [actions] or [defaultActions] only and OK button is shown.
105107
/// Specify the [okActionText] and [cancelActionText] when no icons should be used for the default actions.
106108
/// When default actions are used, this method will return `true` when the user pressed `ok` and `false` after selecting `cancel`.
107-
static Future showWidgetDialog(
109+
static Future<T?> showWidgetDialog<T>(
108110
BuildContext context,
109111
Widget content, {
110112
String? title,
@@ -134,7 +136,7 @@ class DialogHelper {
134136
},
135137
];
136138
if (PlatformInfo.isCupertino) {
137-
return showCupertinoDialog(
139+
return showCupertinoDialog<T>(
138140
context: context,
139141
builder: (context) => CupertinoAlertDialog(
140142
title: title == null ? null : Text(title),
@@ -143,7 +145,7 @@ class DialogHelper {
143145
),
144146
);
145147
} else {
146-
return showDialog(
148+
return showDialog<T>(
147149
builder: (context) => AlertDialog(
148150
title: title == null ? null : Text(title),
149151
content: content,

0 commit comments

Comments
 (0)