ezColorPicker function

Future ezColorPicker(
  1. BuildContext context, {
  2. String? title,
  3. required Color startColor,
  4. required void onColorChange(
    1. Color chosenColor
    ),
  5. String? confirmMsg,
  6. required void onConfirm(),
  7. String? denyMsg,
  8. required void onDeny(),
})

Wrap a ColorPicker in an EzAlertDialog

Implementation

Future<dynamic> ezColorPicker(
  BuildContext context, {
  String? title,
  required Color startColor,
  required void Function(Color chosenColor) onColorChange,
  String? confirmMsg,
  required void Function() onConfirm,
  String? denyMsg,
  required void Function() onDeny,
}) {
  return showPlatformDialog(
    context: context,
    builder: (BuildContext dialogContext) {
      final double padding = EzConfig.get(paddingKey);
      final double spacing = EzConfig.get(spacingKey);

      void confirm() {
        onConfirm();
        Navigator.of(dialogContext).pop();
      }

      void deny() {
        onDeny();
        Navigator.of(dialogContext).pop();
      }

      return EzAlertDialog(
        title: Text(
          title ?? EFUILang.of(context)!.csPickerTitle,
          textAlign: TextAlign.center,
        ),
        content: ColorPicker(
          color: startColor,
          mainAxisSize: MainAxisSize.min,
          padding: EdgeInsets.zero,
          spacing: spacing / 2,
          runSpacing: spacing / 2,
          columnSpacing: spacing,
          pickersEnabled: const <ColorPickerType, bool>{
            ColorPickerType.both: false,
            ColorPickerType.primary: false,
            ColorPickerType.accent: false,
            ColorPickerType.bw: false,
            ColorPickerType.custom: false,
            ColorPickerType.customSecondary: false,
            ColorPickerType.wheel: true
          },
          onColorChanged: onColorChange,
          showRecentColors: true,
          enableOpacity: true,
          opacityThumbRadius: min(padding, 25.0),
          opacityTrackHeight: min(padding * 2, 50.0),
          showColorCode: true,
        ),
        materialActions: ezMaterialActions(
          context: context,
          confirmMsg: confirmMsg ?? EFUILang.of(context)!.gApply,
          onConfirm: confirm,
          confirmIsDestructive: true,
          denyMsg: denyMsg ?? EFUILang.of(context)!.gCancel,
          onDeny: deny,
        ),
        cupertinoActions: ezCupertinoActions(
          context: context,
          confirmMsg: confirmMsg ?? EFUILang.of(context)!.gApply,
          onConfirm: confirm,
          confirmIsDestructive: true,
          denyMsg: denyMsg ?? EFUILang.of(context)!.gCancel,
          onDeny: deny,
        ),
        needsClose: false,
      );
    },
  );
}