showQudsYesNoDialog function

Future<void> showQudsYesNoDialog(
  1. BuildContext context, {
  2. Widget? child,
  3. Widget builder(
    1. BuildContext context
    )?,
  4. EdgeInsets insetPadding = _defaultDialogInsetPadding,
  5. Widget? title,
  6. List<Widget>? leadingActions,
  7. AlignmentGeometry alignment = Alignment.center,
  8. Color? backgroundColor,
  9. BorderRadius? borderRadius,
  10. String yesText = 'Yes',
  11. String noText = 'No',
  12. Color? yesColor,
  13. Color? barrierColor,
  14. bool withBlur = false,
  15. Color? noColor,
  16. Function? onYesPressed,
  17. Function? onNoPressed,
  18. bool withAnimatedSize = true,
})

Show two actions dialog with Yes - No.

Implementation

Future<void> showQudsYesNoDialog(BuildContext context,
    {Widget? child,
    Widget Function(BuildContext context)? builder,
    EdgeInsets insetPadding = _defaultDialogInsetPadding,
    Widget? title,
    List<Widget>? leadingActions,
    AlignmentGeometry alignment = Alignment.center,
    Color? backgroundColor,
    BorderRadius? borderRadius,
    String yesText = 'Yes',
    String noText = 'No',
    Color? yesColor,
    Color? barrierColor,
    bool withBlur = false,
    Color? noColor,
    Function? onYesPressed,
    Function? onNoPressed,
    bool withAnimatedSize = true}) async {
  var result = await showQudsDialog(context,
      child: child,
      builder: builder,
      withBlur: withBlur,
      barrierColor: barrierColor,
      insetPadding: insetPadding,
      title: title,
      leadingActions: leadingActions,
      alignment: alignment,
      backgroundColor: backgroundColor,
      withAnimatedSize: withAnimatedSize,
      actions: [
        TextButton(
            style: yesColor == null
                ? null
                : ButtonStyle(
                    foregroundColor: MaterialStateProperty.all(yesColor)),
            onPressed: () {
              Navigator.maybePop(context, 'yes');
            },
            child: Text(yesText)),
        TextButton(
            style: noColor == null
                ? null
                : ButtonStyle(
                    foregroundColor: MaterialStateProperty.all(noColor)),
            onPressed: () {
              Navigator.maybePop(context, 'no');
            },
            child: Text(noText)),
      ]);
  switch (result) {
    case 'yes':
      onYesPressed?.call();
      break;
    case 'no':
      onNoPressed?.call();
      break;
  }
}