ColorPicker constructor Null safety

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.wheel : false},
  7. bool enableShadesSelection = true,
  8. bool includeIndex850 = false,
  9. CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
  10. EdgeInsetsGeometry padding = const EdgeInsets.all(16),
  11. double columnSpacing = 8,
  12. bool enableOpacity = false,
  13. double opacityTrackHeight = 36,
  14. double? opacityTrackWidth,
  15. double opacityThumbRadius = 16,
  16. ColorPickerActionButtons actionButtons = const ColorPickerActionButtons(),
  17. ColorPickerCopyPasteBehavior copyPasteBehavior = const ColorPickerCopyPasteBehavior(),
  18. IconData selectedColorIcon = Icons.check,
  19. double width = 40,
  20. double height = 40,
  21. double spacing = 4,
  22. double runSpacing = 4,
  23. double elevation = 0,
  24. bool hasBorder = false,
  25. double? borderRadius,
  26. Color? borderColor,
  27. double wheelDiameter = 190,
  28. double wheelWidth = 16,
  29. bool wheelHasBorder = false,
  30. Widget? title,
  31. Widget? heading,
  32. Widget? subheading,
  33. Widget? wheelSubheading,
  34. Widget? recentColorsSubheading,
  35. Widget? opacitySubheading,
  36. bool showMaterialName = false,
  37. TextStyle? materialNameTextStyle,
  38. bool showColorName = false,
  39. TextStyle? colorNameTextStyle,
  40. bool showColorCode = false,
  41. bool colorCodeHasColor = false,
  42. TextStyle? colorCodeTextStyle,
  43. @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,
  44. TextStyle? colorCodePrefixStyle,
  45. bool colorCodeReadOnly = false,
  46. bool showColorValue = false,
  47. bool showRecentColors = false,
  48. int maxRecentColors = 5,
  49. List<Color> recentColors = const <Color>[],
  50. ValueChanged<List<Color>>? onRecentColorsChanged,
  51. bool enableTooltips = true,
  52. Color? selectedPickerTypeColor,
  53. TextStyle? pickerTypeTextStyle,
  54. Map<ColorPickerType, String> pickerTypeLabels = const <ColorPickerType, String>{ColorPickerType.primary : _selectPrimaryLabel, ColorPickerType.accent : _selectAccentLabel, ColorPickerType.bw : _selectBlackWhiteLabel, ColorPickerType.both : _selectBothLabel, ColorPickerType.custom : _selectCustomLabel, ColorPickerType.wheel : _selectWheelAnyLabel},
  55. Map<ColorSwatch<Object>, String> customColorSwatchesAndNames = const <ColorSwatch<Object>, String>{}}
)

Default constructor for the color picker.

Implementation

const ColorPicker({
  Key? 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.wheel: false,
  },
  this.enableShadesSelection = true,
  this.includeIndex850 = false,
  // Layout
  this.crossAxisAlignment = CrossAxisAlignment.center,
  this.padding = const EdgeInsets.all(16),
  this.columnSpacing = 8,
  // 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.spacing = 4,
  this.runSpacing = 4,
  this.elevation = 0,
  this.hasBorder = false,
  this.borderRadius,
  this.borderColor,
  this.wheelDiameter = 190,
  this.wheelWidth = 16,
  this.wheelHasBorder = false,
  // Title, headings and sub headings used by the color picker.
  this.title,
  this.heading,
  this.subheading,
  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.wheel: _selectWheelAnyLabel,
  },
  // Custom color swatches and name map for the custom color swatches.
  this.customColorSwatchesAndNames = const <ColorSwatch<Object>, String>{},
  //
})  : assert(columnSpacing >= 0 && columnSpacing <= 300,
          'The picker item column spacing must be 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.'),
      super(key: key);