ColorPicker constructor
const
ColorPicker(
- {Key? key,
- Color color = Colors.blue,
- required ValueChanged<
Color> onColorChanged, - ValueChanged<
Color> ? onColorChangeStart, - ValueChanged<
Color> ? onColorChangeEnd, - Map<
ColorPickerType, bool> pickersEnabled = const <ColorPickerType, bool>{ColorPickerType.both : false, ColorPickerType.primary : true, ColorPickerType.accent : true, ColorPickerType.bw : false, ColorPickerType.custom : false, ColorPickerType.customSecondary : false, ColorPickerType.wheel : false}, - bool enableShadesSelection = true,
- bool includeIndex850 = false,
- bool enableTonalPalette = false,
- CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
- EdgeInsetsGeometry padding = const EdgeInsets.all(16),
- double columnSpacing = 8,
- double? toolbarSpacing,
- double? shadesSpacing,
- bool enableOpacity = false,
- double opacityTrackHeight = 36,
- double? opacityTrackWidth,
- double opacityThumbRadius = 16,
- ColorPickerActionButtons actionButtons = const ColorPickerActionButtons(),
- ColorPickerCopyPasteBehavior copyPasteBehavior = const ColorPickerCopyPasteBehavior(),
- IconData selectedColorIcon = Icons.check,
- double width = 40,
- double height = 40,
- bool tonalColorSameSize = false,
- double spacing = 4,
- double runSpacing = 4,
- double elevation = 0,
- bool hasBorder = false,
- double? borderRadius,
- Color? borderColor,
- double wheelDiameter = 190,
- double wheelWidth = 16,
- double wheelSquarePadding = 0,
- double wheelSquareBorderRadius = 4,
- bool wheelHasBorder = false,
- Widget? title,
- Widget? heading,
- Widget? subheading,
- Widget? tonalSubheading,
- Widget? wheelSubheading,
- Widget? recentColorsSubheading,
- Widget? opacitySubheading,
- bool showMaterialName = false,
- TextStyle? materialNameTextStyle,
- bool showColorName = false,
- TextStyle? colorNameTextStyle,
- bool showColorCode = false,
- bool colorCodeHasColor = false,
- TextStyle? colorCodeTextStyle,
- @Deprecated('This property is deprecated and no longer has any function. ' 'It was removed in v2.0.0. To modify the copy icon on the color code ' 'entry field, define the `ColorPickerCopyPasteBehavior(copyIcon: ' 'myIcon)` and provide it via the `copyPasteBehavior` property.') IconData? colorCodeIcon,
- TextStyle? colorCodePrefixStyle,
- bool colorCodeReadOnly = false,
- bool showColorValue = false,
- bool showRecentColors = false,
- int maxRecentColors = 5,
- List<
Color> recentColors = const <Color>[], - ValueChanged<
List< ? onRecentColorsChanged,Color> > - bool enableTooltips = true,
- Color? selectedPickerTypeColor,
- TextStyle? pickerTypeTextStyle,
- Map<
ColorPickerType, String> pickerTypeLabels = const <ColorPickerType, String>{ColorPickerType.primary : _selectPrimaryLabel, ColorPickerType.accent : _selectAccentLabel, ColorPickerType.bw : _selectBlackWhiteLabel, ColorPickerType.both : _selectBothLabel, ColorPickerType.custom : _selectCustomLabel, ColorPickerType.customSecondary : _selectCustomSecondaryLabel, ColorPickerType.wheel : _selectWheelAnyLabel}, - Map<
ColorSwatch< customColorSwatchesAndNames = const <ColorSwatch<Object>, String>{},Object> , String> - Map<
ColorSwatch< customSecondaryColorSwatchesAndNames = const <ColorSwatch<Object>, String>{}}Object> , String>
Default constructor for the color picker.
Implementation
const ColorPicker({
super.key,
// Core properties, set color and change callbacks.
this.color = Colors.blue,
required this.onColorChanged,
this.onColorChangeStart,
this.onColorChangeEnd,
// Color picker types shown and used by the color picker.
this.pickersEnabled = const <ColorPickerType, bool>{
ColorPickerType.both: false,
ColorPickerType.primary: true,
ColorPickerType.accent: true,
ColorPickerType.bw: false,
ColorPickerType.custom: false,
ColorPickerType.customSecondary: false,
ColorPickerType.wheel: false,
},
this.enableShadesSelection = true,
this.includeIndex850 = false,
this.enableTonalPalette = false,
// Layout
this.crossAxisAlignment = CrossAxisAlignment.center,
this.padding = const EdgeInsets.all(16),
this.columnSpacing = 8,
this.toolbarSpacing,
this.shadesSpacing,
// Opacity slider
this.enableOpacity = false,
this.opacityTrackHeight = 36,
this.opacityTrackWidth,
this.opacityThumbRadius = 16,
// Picker action buttons and copy paste behavior.
this.actionButtons = const ColorPickerActionButtons(),
this.copyPasteBehavior = const ColorPickerCopyPasteBehavior(),
this.selectedColorIcon = Icons.check,
// Picker item and wheel picker properties.
this.width = 40,
this.height = 40,
this.tonalColorSameSize = false,
this.spacing = 4,
this.runSpacing = 4,
this.elevation = 0,
this.hasBorder = false,
this.borderRadius,
this.borderColor,
this.wheelDiameter = 190,
this.wheelWidth = 16,
this.wheelSquarePadding = 0,
this.wheelSquareBorderRadius = 4,
this.wheelHasBorder = false,
// Title, headings and sub headings used by the color picker.
this.title,
this.heading,
this.subheading,
this.tonalSubheading,
this.wheelSubheading,
this.recentColorsSubheading,
this.opacitySubheading,
// Toggles to show color names and codes and their text styles.
this.showMaterialName = false,
this.materialNameTextStyle,
this.showColorName = false,
this.colorNameTextStyle,
this.showColorCode = false,
this.colorCodeHasColor = false,
this.colorCodeTextStyle,
@Deprecated('This property is deprecated and no longer has any function. '
'It was removed in v2.0.0. To modify the copy icon on the color code '
'entry field, define the `ColorPickerCopyPasteBehavior(copyIcon: '
'myIcon)` and provide it via the `copyPasteBehavior` property.')
this.colorCodeIcon,
this.colorCodePrefixStyle,
this.colorCodeReadOnly = false,
this.showColorValue = false,
// Toggles showing the recent colors selection.
this.showRecentColors = false,
this.maxRecentColors = 5,
this.recentColors = const <Color>[],
this.onRecentColorsChanged,
// Enable tooltips
this.enableTooltips = true,
// Segmented color picker selector control properties.
this.selectedPickerTypeColor,
this.pickerTypeTextStyle,
this.pickerTypeLabels = const <ColorPickerType, String>{
ColorPickerType.primary: _selectPrimaryLabel,
ColorPickerType.accent: _selectAccentLabel,
ColorPickerType.bw: _selectBlackWhiteLabel,
ColorPickerType.both: _selectBothLabel,
ColorPickerType.custom: _selectCustomLabel,
ColorPickerType.customSecondary: _selectCustomSecondaryLabel,
ColorPickerType.wheel: _selectWheelAnyLabel,
},
// Custom color, swatches and name map for the custom color swatches.
this.customColorSwatchesAndNames = const <ColorSwatch<Object>, String>{},
this.customSecondaryColorSwatchesAndNames =
const <ColorSwatch<Object>, String>{},
//
}) : assert(columnSpacing >= 0 && columnSpacing <= 300,
'The picker item column spacing must be from 0 to max 300 dp.'),
assert(
toolbarSpacing == null ||
(toolbarSpacing >= 0 && toolbarSpacing <= 300),
'The spacing must be null or from 0 to max 300 dp.'),
assert(
shadesSpacing == null ||
(shadesSpacing >= 0 && shadesSpacing <= 300),
'The spacing must be null or from 0 to max 300 dp.'),
assert(spacing >= 0 && spacing <= 50,
'The picker item spacing must be from 0 to max 50 dp.'),
assert(runSpacing >= 0 && runSpacing <= 50,
'The picker item runSpacing must be from 0 to max 50 dp.'),
assert(elevation >= 0, 'The picker item elevation must be >= 0 dp.'),
assert(width >= 15 && width <= 150,
'The pick item width must be from 15 to max 150 dp.'),
assert(height >= 15 && height <= 150,
'The pick item height must be from 15 to max 150 dp.'),
assert(
borderRadius == null || (borderRadius >= 0 && borderRadius <= 50),
'The pick item borderRadius must be null or from 0 to max 50 dp.'),
assert(opacityTrackWidth == null || opacityTrackWidth >= 150,
'The opacity slider track width must be null or >= 150.'),
assert(opacityTrackHeight >= 8 && opacityTrackHeight <= 50,
'The opacity slider track height must be from 8 to max 50 dp.'),
assert(opacityThumbRadius >= 12 && opacityThumbRadius <= 30,
'The opacity slider thumb radius must be from 12 to max 30 dp.'),
assert(wheelDiameter >= 100 && wheelDiameter <= 500,
'The wheel diameter must be from 100 to max 500 dp.'),
assert(wheelWidth >= 4 && wheelWidth <= 50,
'The color wheel width must be from 4 to max 50 dp.'),
assert(
maxRecentColors >= _minRecentColors &&
maxRecentColors <= _maxRecentColors,
'The maxRecentColors must be >= $_minRecentColors '
'and <= $_maxRecentColors.');