showPrinterConfirmDialog function
Shows a premium styled confirmation dialog.
Returns true only when the confirm button was tapped.
Implementation
Future<bool> showPrinterConfirmDialog(
BuildContext context, {
required String title,
required String message,
String confirmLabel = 'Yes',
String cancelLabel = 'No',
bool destructive = false,
}) async {
final bool? result = await showDialog<bool>(
context: context,
builder: (BuildContext dialogContext) {
final Color actionColor = destructive
? PrinterSdkConfig.errorColor
: PrinterSdkConfig.primaryColor;
return AlertDialog(
backgroundColor: PrinterSdkConfig.surfaceColor,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(PrinterSdkConfig.borderRadius),
),
title: Text(
title,
style: TextStyle(
color: PrinterSdkConfig.textPrimaryColor,
fontWeight: FontWeight.w700,
fontSize: 17,
),
),
content: Text(
message,
style: TextStyle(
color: PrinterSdkConfig.textSecondaryColor,
fontSize: 14,
height: 1.4,
),
),
actionsPadding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
style: TextButton.styleFrom(
foregroundColor: PrinterSdkConfig.textSecondaryColor,
),
child: Text(cancelLabel),
),
FilledButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
style: FilledButton.styleFrom(
backgroundColor: actionColor,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Text(confirmLabel),
),
],
);
},
);
return result ?? false;
}