showMaterialSwatchPicker function

void showMaterialSwatchPicker({
  1. required BuildContext context,
  2. String title = "Pick a color",
  3. required Color selectedColor,
  4. Color? headerColor,
  5. Color? headerTextColor,
  6. Color? backgroundColor,
  7. Color? buttonTextColor,
  8. String? confirmText,
  9. String? cancelText,
  10. double? maxLongSide,
  11. double? maxShortSide,
  12. ValueChanged<Color>? onChanged,
  13. VoidCallback? onConfirmed,
  14. VoidCallback? onCancelled,
})

Allows selection of a color from swatches

Implementation

void showMaterialSwatchPicker({
  required BuildContext context,
  String title = "Pick a color",
  required Color selectedColor,
  Color? headerColor,
  Color? headerTextColor,
  Color? backgroundColor,
  Color? buttonTextColor,
  String? confirmText,
  String? cancelText,
  double? maxLongSide,
  double? maxShortSide,
  ValueChanged<Color>? onChanged,
  VoidCallback? onConfirmed,
  VoidCallback? onCancelled,
}) {
  showDialog<Color>(
    context: context,
    builder: (BuildContext context) {
      return OrientationBuilder(
        builder: (context, orientation) {
          return ResponsiveDialog(
            context: context,
            title: title,
            headerColor: headerColor,
            headerTextColor: headerTextColor,
            backgroundColor: backgroundColor,
            buttonTextColor: buttonTextColor,
            confirmText: confirmText,
            cancelText: cancelText,
            maxLongSide: maxLongSide,
            maxShortSide: maxLongSide,
            child: BlockPicker(
              pickerColor: selectedColor,
              onColorChanged: (color) => selectedColor = color,
            ),
            okPressed: () => Navigator.of(context).pop(selectedColor),
          );
        },
      );
    },
  ).then((selection) {
    if (onChanged != null && selection != null) onChanged(selection);
    if (onCancelled != null && selection == null) onCancelled();
    if (onConfirmed != null && selection != null) onConfirmed();
  });
}