showMaterialSwatchPicker function
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,
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();
});
}