showNAlertDialog<T> function

Future<T?> showNAlertDialog<T>({
  1. required BuildContext context,
  2. required String title,
  3. String? message,
  4. String? confirmLabel = 'OK',
  5. String? cancelLabel,
  6. T? confirmValue,
  7. T? cancelValue,
  8. VoidCallback? onConfirm,
  9. Color? confirmColor,
  10. AppFeedbackType type = AppFeedbackType.info,
  11. bool barrierDismissible = true,
})

Shows an alert dialog and returns the pressed action.

Implementation

Future<T?> showNAlertDialog<T>({
  required BuildContext context,
  required String title,
  String? message,
  String? confirmLabel = 'OK',
  String? cancelLabel,
  T? confirmValue,
  T? cancelValue,
  VoidCallback? onConfirm,
  Color? confirmColor,
  AppFeedbackType type = AppFeedbackType.info,
  bool barrierDismissible = true,
}) =>
    showDialog<T>(
      context: context,
      barrierDismissible: barrierDismissible,
      child: Dialog(
        title: title,
        subtitle: message,
        icon: _iconFor(type),
        actions: <Widget>[
          if (cancelLabel != null)
            TextButton(
              onPressed: () => Navigator.of(context).pop(cancelValue),
              child: Text(cancelLabel),
            ),
          FilledButton(
            onPressed: () {
              onConfirm?.call();
              Navigator.of(context).pop(confirmValue);
            },
            style: FilledButton.styleFrom(
              backgroundColor: confirmColor ?? AppColors.forFeedback(type),
            ),
            child: Text(confirmLabel ?? 'OK'),
          ),
        ],
      ),
    );