showWidgetDialog<T> static method
Future<T?>
showWidgetDialog<T>(
- BuildContext context,
- Widget content, {
- String? title,
- List<
Widget> ? actions, - DialogActions defaultActions = DialogActions.ok,
- String? okActionText,
- String? cancelActionText,
Shows a dialog with the given content
.
Set the title
to display the title on top
Specify custom actions
to provide dialog specific actions, alternatively specify the defaultActions
. Without actions
or defaultActions
only and OK button is shown.
Specify the okActionText
and cancelActionText
when no icons should be used for the default actions.
When default actions are used, this method will return true
when the user pressed ok
and false
after selecting cancel
.
Implementation
static Future<T?> showWidgetDialog<T>(
BuildContext context,
Widget content, {
String? title,
List<Widget>? actions,
DialogActions defaultActions = DialogActions.ok,
String? okActionText,
String? cancelActionText,
}) {
actions ??= [
if (defaultActions == DialogActions.cancel ||
defaultActions == DialogActions.okAndCancel) ...{
PlatformTextButton(
child: cancelActionText != null
? PlatformText(cancelActionText)
: Icon(CommonPlatformIcons.cancel),
onPressed: () => Navigator.of(context).pop(false),
),
},
if (defaultActions == DialogActions.ok ||
defaultActions == DialogActions.okAndCancel) ...{
PlatformTextButton(
child: okActionText != null
? PlatformText(okActionText)
: Icon(CommonPlatformIcons.ok),
onPressed: () => Navigator.of(context).pop(true),
),
},
];
if (PlatformInfo.isCupertino) {
return showCupertinoDialog<T>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: title == null ? null : Text(title),
content: content,
actions: actions!,
),
);
} else {
return showDialog<T>(
builder: (context) => AlertDialog(
title: title == null ? null : Text(title),
content: content,
actions: actions,
),
context: context,
);
}
}