Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions example/lib/pickers/hsv_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class _HSVColorPickerExampleState extends State<HSVColorPickerExample> {
// Picker 1
PaletteType _paletteType = PaletteType.hsl;
bool _enableAlpha = true;
bool _enableSlider = true;
bool _enableColorIndicator = true;
bool _displayThumbColor = true;
final List<ColorLabelType> _labelTypes = [ColorLabelType.hsl, ColorLabelType.hsv];
bool _displayHexInputBar = false;
Expand Down Expand Up @@ -84,6 +86,8 @@ class _HSVColorPickerExampleState extends State<HSVColorPickerExample> {
colorPickerWidth: 300,
pickerAreaHeightPercent: 0.7,
enableAlpha: _enableAlpha,
enableSlider: _enableSlider,
enableColorIndicator: _enableColorIndicator,
labelTypes: _labelTypes,
displayThumbColor: _displayThumbColor,
paletteType: _paletteType,
Expand Down Expand Up @@ -126,6 +130,8 @@ ColorPicker(
colorPickerWidth: 300,
pickerAreaHeightPercent: 0.7,
enableAlpha: $_enableAlpha,
enableSlider: $_enableSlider,
enableColorIndicator: $_enableColorIndicator,
labelTypes: $_labelTypes,
displayThumbColor: $_displayThumbColor,
paletteType: $_paletteType,
Expand Down Expand Up @@ -159,6 +165,16 @@ ColorPicker(
value: _enableAlpha,
onChanged: (bool value) => setState(() => _enableAlpha = !_enableAlpha),
),
SwitchListTile(
title: const Text('Enable Slider'),
value: _enableSlider,
onChanged: (bool value) => setState(() => _enableSlider = !_enableSlider),
),
SwitchListTile(
title: const Text('Enable Color Indicator'),
value: _enableColorIndicator,
onChanged: (bool value) => setState(() => _enableColorIndicator = !_enableColorIndicator),
),
SwitchListTile(
title: const Text('Display Thumb Color in slider'),
value: _displayThumbColor,
Expand Down
48 changes: 28 additions & 20 deletions lib/src/colorpicker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ColorPicker extends StatefulWidget {
this.onHsvColorChanged,
this.paletteType = PaletteType.hsvWithHue,
this.enableAlpha = true,
this.enableSlider = true,
this.enableColorIndicator = true,
@Deprecated('Use empty list in [labelTypes] to disable label.') this.showLabel = true,
this.labelTypes = const [ColorLabelType.rgb, ColorLabelType.hsv, ColorLabelType.hsl],
@Deprecated('Use Theme.of(context).textTheme.bodyText1 & 2 to alter text style.') this.labelTextStyle,
Expand All @@ -38,6 +40,8 @@ class ColorPicker extends StatefulWidget {
final ValueChanged<HSVColor>? onHsvColorChanged;
final PaletteType paletteType;
final bool enableAlpha;
final bool enableSlider;
final bool enableColorIndicator;
final bool showLabel;
final List<ColorLabelType> labelTypes;
final TextStyle? labelTextStyle;
Expand Down Expand Up @@ -289,19 +293,21 @@ class _ColorPickerState extends State<ColorPicker> {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
onTap: () => setState(() {
if (widget.onHistoryChanged != null && !colorHistory.contains(currentHsvColor.toColor())) {
colorHistory.add(currentHsvColor.toColor());
widget.onHistoryChanged!(colorHistory);
}
}),
child: ColorIndicator(currentHsvColor),
),
if (widget.enableColorIndicator)
GestureDetector(
onTap: () => setState(() {
if (widget.onHistoryChanged != null && !colorHistory.contains(currentHsvColor.toColor())) {
colorHistory.add(currentHsvColor.toColor());
widget.onHistoryChanged!(colorHistory);
}
}),
child: ColorIndicator(currentHsvColor),
),
Expanded(
child: Column(
children: <Widget>[
SizedBox(height: 40.0, width: widget.colorPickerWidth - 75.0, child: sliderByPaletteType()),
if (widget.enableSlider)
SizedBox(height: 40.0, width: widget.colorPickerWidth - 75.0, child: sliderByPaletteType()),
if (widget.enableAlpha)
SizedBox(
height: 40.0,
Expand Down Expand Up @@ -368,18 +374,20 @@ class _ColorPickerState extends State<ColorPicker> {
Row(
children: <Widget>[
const SizedBox(width: 20.0),
GestureDetector(
onTap: () => setState(() {
if (widget.onHistoryChanged != null && !colorHistory.contains(currentHsvColor.toColor())) {
colorHistory.add(currentHsvColor.toColor());
widget.onHistoryChanged!(colorHistory);
}
}),
child: ColorIndicator(currentHsvColor),
),
if (widget.enableColorIndicator)
GestureDetector(
onTap: () => setState(() {
if (widget.onHistoryChanged != null && !colorHistory.contains(currentHsvColor.toColor())) {
colorHistory.add(currentHsvColor.toColor());
widget.onHistoryChanged!(colorHistory);
}
}),
child: ColorIndicator(currentHsvColor),
),
Column(
children: <Widget>[
SizedBox(height: 40.0, width: 260.0, child: sliderByPaletteType()),
if (widget.enableSlider)
SizedBox(height: 40.0, width: 260.0, child: sliderByPaletteType()),
if (widget.enableAlpha)
SizedBox(height: 40.0, width: 260.0, child: colorPickerSlider(TrackType.alpha)),
],
Expand Down