showAlertDialog function
void
showAlertDialog(
- BuildContext context, {
- required String title,
- required Widget child,
- double height = 350,
- String confirmText = "Confirm",
- String cancelText = "Cancel",
- VoidCallback? onConfirm,
- VoidCallback? onCancel,
Displays an alert dialog with the given context
.
The context
parameter is required and represents the current build context.
Additional optional parameters can be provided to customize the appearance and behavior of the alert dialog.
Example usage:
showAlertDialog(context, title: 'Alert', message: 'This is an alert message');
Implementation
void showAlertDialog(
BuildContext context, {
required String title,
required Widget child,
double height = 350,
String confirmText = "Confirm",
String cancelText = "Cancel",
VoidCallback? onConfirm,
VoidCallback? onCancel,
}) {
showDialog(
context: context,
builder: (context) => Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
backgroundColor: Theme.of(context).colorScheme.background,
child: Container(
height: height,
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
Container(
height: 75,
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: const BorderRadius.vertical(top: Radius.circular(15)),
),
child: Center(
child: Text(
title,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
fontSize: 23,
),
),
),
),
Expanded(child: child),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
onCancel?.call();
},
child: Text(cancelText),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
onConfirm?.call();
},
child: Text(confirmText),
),
],
),
const SizedBox(height: 10),
],
),
),
),
);
}