show static method
void
show({
- required BuildContext context,
- required String title,
- Widget? content,
- List<
Widget> ? actions, - bool barrierDismissible = false,
- EdgeInsets? paddingAll,
- EdgeInsets? padding,
- Widget? icon,
- double? width,
- BorderRadiusGeometry? borderRadius,
- Color? dividerColor,
Displays a customizable dialog.
context(required): TheBuildContextto show the dialog from.title(required): Title text shown in the header.content: Optional body widget shown below the title.actions: Optional list of buttons shown in the footer.barrierDismissible: Tap-outside-to-close. Defaults tofalse.paddingAll: Padding for the header and content sections. Defaults toEdgeInsets.all(16).padding: Padding for the actions footer. Defaults toEdgeInsets.symmetric(horizontal: 20, vertical: 16).icon: Optional leading icon shown before the title.width: Dialog width. Defaults to400.borderRadius: Dialog corner radius. Defaults toRadius.circular(12).dividerColor: Color of the dividers. Defaults toColors.grey.
Implementation
static void show({
required BuildContext context,
required String title,
Widget? content,
List<Widget>? actions,
bool barrierDismissible = false,
EdgeInsets? paddingAll,
EdgeInsets? padding,
Widget? icon,
double? width,
BorderRadiusGeometry? borderRadius,
Color? dividerColor,
}) {
showDialog(
barrierDismissible: barrierDismissible,
context: context,
builder: (_) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius:
borderRadius ?? const BorderRadius.all(Radius.circular(12)),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
child: SizedBox(
width: width ?? 400,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Padding(
padding: paddingAll ?? const EdgeInsets.all(16),
child: Row(
children: [
if (icon != null) ...[
icon,
const SizedBox(width: 8),
],
Expanded(
child: Text(
title,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
InkWell(
onTap: () => Navigator.pop(context),
child: Icon(
Icons.close,
size: 20,
color: Colors.black.withValues(alpha: 0.5),
),
),
],
),
),
// Content
if (content != null) ...[
Divider(
height: 0,
thickness: 1,
color: dividerColor ?? Colors.grey),
Padding(
padding: paddingAll ?? const EdgeInsets.all(16),
child: content,
),
],
// Actions
if (actions != null) ...[
Divider(
height: 0,
thickness: 1,
color: dividerColor ?? Colors.grey),
Padding(
padding: padding ??
const EdgeInsets.symmetric(
horizontal: 20, vertical: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: actions,
),
),
],
],
),
),
);
},
);
}