showPopUpConfirmation static method
void
showPopUpConfirmation(
- BuildContext context, {
- String title = '',
- String cancelActionLabel = 'Cancel',
- String confirmActionLabel = 'Confirm',
- double borderRadius = 16.0,
- double confirmationContainerPadding = 5.0,
- double confirmationContainerMargin = 10.0,
- Color themColor = const Color(0xFF619E51),
- Color confirmationButtomThemColor = const Color(0xFF619E51),
- MainAxisAlignment actionButtomAlignment = MainAxisAlignment.center,
- Widget? confirmationContent,
- List<
Widget> customConfirmationActionButtons = const [], - VoidCallback? onConfirm,
Implementation
static void showPopUpConfirmation(
BuildContext context, {
String title = '',
String cancelActionLabel = 'Cancel',
String confirmActionLabel = 'Confirm',
double borderRadius = 16.0,
double confirmationContainerPadding = 5.0,
double confirmationContainerMargin = 10.0,
Color themColor = const Color(0xFF619E51),
Color confirmationButtomThemColor = const Color(0xFF619E51),
MainAxisAlignment actionButtomAlignment = MainAxisAlignment.center,
Widget? confirmationContent,
List<Widget> customConfirmationActionButtons = const [],
VoidCallback? onConfirm,
}) async {
double width = MediaQuery.of(context).size.width;
// Display the dialog using showDialog
return showDialog(
context: context,
builder: (BuildContext context) {
// Create a SimpleDialog with a custom shape, padding,
// margin, background color, and alignment
return SimpleDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
insetPadding: EdgeInsets.all(confirmationContainerMargin),
titlePadding: title.isNotEmpty
? EdgeInsets.all(confirmationContainerPadding)
: EdgeInsets.all(0.0),
backgroundColor: Colors.white,
alignment: Alignment.center,
// Display the title if it is not empty
title: Visibility(
visible: title.isNotEmpty,
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(
vertical: confirmationContainerPadding,
),
child: Text(
title,
style: const TextStyle().copyWith(
color: themColor,
fontSize: 20.0,
fontWeight: FontWeight.w400,
),
),
),
),
// Add padding to the content
contentPadding: EdgeInsets.all(confirmationContainerPadding),
children: [
// Display the confirmation content if it is not null
Visibility(
visible: confirmationContent != null,
child: Container(
width: width,
margin: EdgeInsets.symmetric(
horizontal: confirmationContainerPadding,
vertical: confirmationContainerMargin,
),
child: confirmationContent,
),
),
// Display the custom confirmation action buttons or a default row of buttons
Container(
width: width,
margin: EdgeInsets.symmetric(
vertical: confirmationContainerPadding,
),
child: Row(
mainAxisAlignment: actionButtomAlignment,
children: customConfirmationActionButtons.isNotEmpty
? customConfirmationActionButtons
: [
Container(
margin: EdgeInsets.symmetric(
horizontal: 5.0,
),
child: OutlinedButton(
style: ButtonStyle().copyWith(
foregroundColor:
MaterialStatePropertyAll(themColor),
side: MaterialStatePropertyAll(
BorderSide().copyWith(
color: themColor,
),
),
textStyle: MaterialStateProperty.all(
TextStyle().copyWith(
color: themColor,
fontSize: 14.0,
fontWeight: FontWeight.w500,
),
),
),
onPressed: () => Navigator.pop(context),
child: Text(cancelActionLabel),
),
),
Container(
margin: EdgeInsets.symmetric(
horizontal: 5.0,
),
child: FilledButton(
style: ButtonStyle().copyWith(
backgroundColor: MaterialStateProperty.all(
confirmationButtomThemColor),
textStyle: MaterialStateProperty.all(
TextStyle().copyWith(
fontSize: 14.0,
fontWeight: FontWeight.w500,
),
),
),
onPressed: onConfirm,
child: Text(confirmActionLabel),
),
),
],
),
)
],
);
},
);
}