YurAlertDialog function
dynamic
YurAlertDialog({
- required BuildContext context,
- required String title,
- required String message,
- required String buttonText,
- required dynamic onConfirm(),
- DialogType dialogType = DialogType.confirmation,
- String? message2,
- String? message3,
- dynamic onCancel()?,
- String? cancelText,
- Color barrierColor = Colors.black54,
- double elevasi = 24,
- dynamic textAlign = TextAlign.justify,
- int maxMessageLine = 4,
- FontWeight fontWeight = FontWeight.w400,
- bool isDismissable = true,
Implementation
YurAlertDialog({
required BuildContext context,
required String title,
required String message,
required String buttonText,
required Function() onConfirm,
DialogType dialogType = DialogType.confirmation,
String? message2,
String? message3,
Function()? onCancel,
String? cancelText,
Color barrierColor = Colors.black54,
double elevasi = 24,
textAlign = TextAlign.justify,
int maxMessageLine = 4,
FontWeight fontWeight = FontWeight.w400,
bool isDismissable = true,
}) async {
return WidgetsBinding.instance.addPostFrameCallback((_) async {
await showDialog(
context: context,
barrierDismissible: isDismissable
? dialogType == DialogType.confirmation
? true
: false
: false,
barrierColor: barrierColor.withOpacity(0.5),
useSafeArea: true,
useRootNavigator: true,
builder: (BuildContext context) {
return PopScope(
canPop: (dialogType == DialogType.confirmation),
onPopInvoked: (didPop) {
if (!didPop) Future.delayed(500.ms, () => onConfirm());
},
child: AlertDialog(
alignment: Alignment.center,
elevation: elevasi,
scrollable: true,
shadowColor: Colors.black,
actionsPadding: e12,
actionsAlignment: MainAxisAlignment.spaceAround,
actionsOverflowAlignment: OverflowBarAlignment.center,
actionsOverflowButtonSpacing: 16,
buttonPadding: eH16,
insetPadding: e16,
titlePadding: e16,
actionsOverflowDirection: VerticalDirection.down,
surfaceTintColor: Colors.grey.shade100,
backgroundColor: Colors.white,
clipBehavior: Clip.antiAliasWithSaveLayer,
semanticLabel: title,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
YurText(
fontSize: 20,
text: title,
color: primaryRed,
maxLines: 3,
textAlign: TextAlign.center,
),
if (dialogType == DialogType.confirmation)
IconButton(
onPressed: () {
if (onCancel != null) {
onCancel();
} else {
Get.back();
}
},
icon: const YurIcon(
icon: Icons.cancel_outlined,
color: primaryRed,
),
)
],
),
const YurDivider(),
],
),
content: SingleChildScrollView(
physics: const ClampingScrollPhysics(),
child: Column(
children: [
YurText(
fontWeight: fontWeight,
text: message,
textAlign: textAlign,
letterSpacing: 0.2,
maxLines: maxMessageLine,
color: Colors.black87,
),
if (message2 != null)
Column(
children: [
gap8,
YurText(
fontWeight: fontWeight,
text: message2,
textAlign: textAlign,
letterSpacing: 0.2,
maxLines: maxMessageLine,
color: primaryRed,
),
],
),
if (message3 != null)
Column(
children: [
gap8,
YurText(
fontWeight: fontWeight,
text: message3,
textAlign: textAlign,
letterSpacing: 0.2,
maxLines: maxMessageLine,
color: primaryRed,
),
],
),
],
),
),
shape: const RoundedRectangleBorder(borderRadius: br16),
actions: [
Column(
children: [
const YurDivider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
if (dialogType == DialogType.confirmation)
Expanded(
child: YurButton(
text: cancelText ?? "Batal",
buttonStyle: BStyle.secondaryRed,
fontSize: 12,
onPressed: () =>
onCancel != null ? onCancel() : Get.back(),
)),
if (dialogType == DialogType.confirmation) gap8,
Expanded(
child: YurButton(
text: buttonText,
buttonStyle: BStyle.primaryRed,
fontSize: 12,
onPressed: () {
Future.delayed(500.ms, () {
onConfirm();
Get.back();
YurLog(name: "YurcallDialog", title);
});
},
)),
],
)
],
),
],
),
);
},
);
});
}