defaultDialog<T> method

Future<T> defaultDialog<T>(
  1. {String title = "Alert",
  2. TextStyle titleStyle,
  3. Widget content,
  4. VoidCallback onConfirm,
  5. VoidCallback onCancel,
  6. VoidCallback onCustom,
  7. Color cancelTextColor,
  8. Color confirmTextColor,
  9. String textConfirm,
  10. String textCancel,
  11. String textCustom,
  12. Widget confirm,
  13. Widget cancel,
  14. Widget custom,
  15. Color backgroundColor,
  16. bool barrierDismissible = true,
  17. Color buttonColor,
  18. String middleText = "Dialog made in 3 lines of code",
  19. TextStyle middleTextStyle,
  20. double radius = 20.0,
  21. List<Widget> actions}
)

Custom UI Dialog.

Implementation

Future<T> defaultDialog<T>({
  String title = "Alert",
  TextStyle titleStyle,
  Widget content,
  VoidCallback onConfirm,
  VoidCallback onCancel,
  VoidCallback onCustom,
  Color cancelTextColor,
  Color confirmTextColor,
  String textConfirm,
  String textCancel,
  String textCustom,
  Widget confirm,
  Widget cancel,
  Widget custom,
  Color backgroundColor,
  bool barrierDismissible = true,
  Color buttonColor,
  String middleText = "Dialog made in 3 lines of code",
  TextStyle middleTextStyle,
  double radius = 20.0,
  //   ThemeData themeData,
  List<Widget> actions,
}) {
  var leanCancel = onCancel != null || textCancel != null;
  var leanConfirm = onConfirm != null || textConfirm != null;
  actions ??= [];

  if (cancel != null) {
    actions.add(cancel);
  } else {
    if (leanCancel) {
      actions.add(FlatButton(
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
        onPressed: () {
          onCancel?.call();
          back();
        },
        padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8),
        child: Text(
          textCancel ?? "Cancel",
          style: TextStyle(color: cancelTextColor ?? theme.accentColor),
        ),
        shape: RoundedRectangleBorder(
            side: BorderSide(
                color: buttonColor ?? theme.accentColor,
                width: 2,
                style: BorderStyle.solid),
            borderRadius: BorderRadius.circular(100)),
      ));
    }
  }
  if (confirm != null) {
    actions.add(confirm);
  } else {
    if (leanConfirm) {
      actions.add(FlatButton(
          materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
          color: buttonColor ?? theme.accentColor,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(100)),
          child: Text(
            textConfirm ?? "Ok",
            style: TextStyle(color: confirmTextColor ?? theme.primaryColor),
          ),
          onPressed: () {
            onConfirm?.call();
          }));
    }
  }

  return dialog(
    AlertDialog(
      titlePadding: EdgeInsets.all(8),
      contentPadding: EdgeInsets.all(8),
      backgroundColor: backgroundColor ?? theme.dialogBackgroundColor,
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(radius))),
      title: Text(title, textAlign: TextAlign.center, style: titleStyle),
      content: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          content ??
              Text(middleText ?? "",
                  textAlign: TextAlign.center, style: middleTextStyle),
          SizedBox(height: 16),
          ButtonTheme(
            minWidth: 78.0,
            height: 34.0,
            child: Wrap(
              alignment: WrapAlignment.center,
              spacing: 8,
              runSpacing: 8,
              children: actions,
            ),
          )
        ],
      ),
      // actions: actions, // ?? <Widget>[cancelButton, confirmButton],
      buttonPadding: EdgeInsets.zero,
    ),
    barrierDismissible: barrierDismissible,
  );
}