slideEvent method
Updates the colour for a drag or tap at globalPosition.
getBox is the slider's render box and box its size limits. Called
by the slider's gesture handlers.
Implementation
void slideEvent(RenderBox getBox, BoxConstraints box, Offset globalPosition) {
final double localDx = getBox.globalToLocal(globalPosition).dx - 15.0;
final double progress =
localDx.clamp(0.0, box.maxWidth - 30.0) / (box.maxWidth - 30.0);
switch (trackType) {
case TrackType.hue:
onColorChanged(hsvColor.withHue(progress * 359));
break;
case TrackType.saturation:
onColorChanged(hsvColor.withSaturation(progress));
break;
case TrackType.saturationForHSL:
onColorChanged(hslToHsv(hsvToHsl(hsvColor).withSaturation(progress)));
break;
case TrackType.value:
onColorChanged(hsvColor.withValue(progress));
break;
case TrackType.lightness:
onColorChanged(hslToHsv(hsvToHsl(hsvColor).withLightness(progress)));
break;
case TrackType.red:
onColorChanged(
HSVColor.fromColor(
hsvColor.toColor().withRed((progress * 0xff).round()),
),
);
break;
case TrackType.green:
onColorChanged(
HSVColor.fromColor(
hsvColor.toColor().withGreen((progress * 0xff).round()),
),
);
break;
case TrackType.blue:
onColorChanged(
HSVColor.fromColor(
hsvColor.toColor().withBlue((progress * 0xff).round()),
),
);
break;
case TrackType.alpha:
onColorChanged(
hsvColor.withAlpha(
localDx.clamp(0.0, box.maxWidth - 30.0) / (box.maxWidth - 30.0),
),
);
break;
}
}