ColorPicker constructor

const ColorPicker(
  1. {Key? key,
  2. Color color = Colors.blue,
  3. required ValueChanged<Color> onColorChanged,
  4. ValueChanged<Color>? onColorChangeStart,
  5. ValueChanged<Color>? onColorChangeEnd,
  6. 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},
  7. bool enableShadesSelection = true,
  8. bool includeIndex850 = false,
  9. bool enableTonalPalette = false,
  10. CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
  11. EdgeInsetsGeometry padding = const EdgeInsets.all(16),
  12. double columnSpacing = 8,
  13. double? toolbarSpacing,
  14. double? shadesSpacing,
  15. bool enableOpacity = false,
  16. double opacityTrackHeight = 36,
  17. double? opacityTrackWidth,
  18. double opacityThumbRadius = 16,
  19. ColorPickerActionButtons actionButtons = const ColorPickerActionButtons(),
  20. ColorPickerCopyPasteBehavior copyPasteBehavior = const ColorPickerCopyPasteBehavior(),
  21. IconData selectedColorIcon = Icons.check,
  22. double width = 40,
  23. double height = 40,
  24. bool tonalColorSameSize = false,
  25. double spacing = 4,
  26. double runSpacing = 4,
  27. double elevation = 0,
  28. bool hasBorder = false,
  29. double? borderRadius,
  30. Color? borderColor,
  31. double wheelDiameter = 190,
  32. double wheelWidth = 16,
  33. double wheelSquarePadding = 0,
  34. double wheelSquareBorderRadius = 4,
  35. bool wheelHasBorder = false,
  36. Widget? title,
  37. Widget? heading,
  38. Widget? subheading,
  39. Widget? tonalSubheading,
  40. Widget? wheelSubheading,
  41. Widget? recentColorsSubheading,
  42. Widget? opacitySubheading,
  43. bool showMaterialName = false,
  44. TextStyle? materialNameTextStyle,
  45. bool showColorName = false,
  46. TextStyle? colorNameTextStyle,
  47. bool showColorCode = false,
  48. bool colorCodeHasColor = false,
  49. TextStyle? colorCodeTextStyle,
  50. @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,
  51. TextStyle? colorCodePrefixStyle,
  52. bool colorCodeReadOnly = false,
  53. bool showColorValue = false,
  54. bool showRecentColors = false,
  55. int maxRecentColors = 5,
  56. List<Color> recentColors = const <Color>[],
  57. ValueChanged<List<Color>>? onRecentColorsChanged,
  58. bool enableTooltips = true,
  59. Color? selectedPickerTypeColor,
  60. TextStyle? pickerTypeTextStyle,
  61. 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},
  62. Map<ColorSwatch<Object>, String> customColorSwatchesAndNames = const <ColorSwatch<Object>, String>{},
  63. Map<ColorSwatch<Object>, String> customSecondaryColorSwatchesAndNames = const <ColorSwatch<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.');