From d0e0bf3571b5010356bcb58d77c0b31a984d750b Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sun, 10 Feb 2019 18:24:54 +0200 Subject: [PATCH] Current color for color picker fix --- .../common/light_color_picker.dart | 28 ++++++++++++++----- .../controls/light_controls.dart | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/entity_widgets/common/light_color_picker.dart b/lib/entity_widgets/common/light_color_picker.dart index 584b987..f3052f3 100644 --- a/lib/entity_widgets/common/light_color_picker.dart +++ b/lib/entity_widgets/common/light_color_picker.dart @@ -24,19 +24,28 @@ class LightColorPickerState extends State { @override Widget build(BuildContext context) { - List colors = []; + List colorRows = []; Border border; + bool isSomethingSelected = false; Logger.d("Current colotfor picker: [${widget.color.hue}, ${widget.color.saturation}]"); for (double saturation = 1.0; saturation >= (0.0 + widget.saturationStep); saturation = double.parse((saturation - widget.saturationStep).toStringAsFixed(2))) { List rowChildren = []; - Logger.d("$saturation"); + //Logger.d("$saturation"); + double roundedSaturation = double.parse(widget.color.saturation.toStringAsFixed(1)); + //Logger.d("Rounded saturation=$roundedSaturation"); for (double hue = 0; hue <= (365 - widget.hueStep); hue += widget.hueStep) { - if (widget.color.hue.round() >= hue && widget.color.hue.round() < (hue+widget.hueStep) && widget.color.saturation == saturation) { + bool isExactHue = widget.color.hue.round() == hue; + bool isHueInRange = widget.color.hue.round() > hue && widget.color.hue.round() < (hue+widget.hueStep); + bool isExactSaturation = roundedSaturation == saturation; + bool isSaturationInRange = roundedSaturation > saturation && roundedSaturation < double.parse((saturation+widget.saturationStep).toStringAsFixed(1)); + if ((isExactHue || isHueInRange) && (isExactSaturation || isSaturationInRange)) { + //Logger.d("$isExactHue $isHueInRange $isExactSaturation $isSaturationInRange (${saturation+widget.saturationStep})"); border = Border.all( width: 2.0, color: Colors.white, ); + isSomethingSelected = true; } else { border = null; } @@ -56,19 +65,23 @@ class LightColorPickerState extends State { ) ); } - colors.add( + colorRows.add( Row( children: rowChildren, ) ); } - colors.add( + colorRows.add( Flexible( child: GestureDetector( child: Container( height: 40.0, decoration: BoxDecoration( - color: Colors.white + color: Colors.white, + border: isSomethingSelected ? null : Border.all( + width: 2.0, + color: Colors.amber[200], + ) ), ), onTap: () => widget.onColorSelected(HSVColor.fromAHSV(1.0, 30.0, 0.0, 1.0)), @@ -78,7 +91,8 @@ class LightColorPickerState extends State { return Padding( child: Column( mainAxisSize: MainAxisSize.min, - children: colors, + crossAxisAlignment: CrossAxisAlignment.center, + children: colorRows, ), padding: widget.padding, ); diff --git a/lib/entity_widgets/controls/light_controls.dart b/lib/entity_widgets/controls/light_controls.dart index cae2f7d..c75e273 100644 --- a/lib/entity_widgets/controls/light_controls.dart +++ b/lib/entity_widgets/controls/light_controls.dart @@ -117,7 +117,7 @@ class _LightControlsWidgetState extends State { return UniversalSlider( title: "Color temperature", leading: Text("Cold", style: TextStyle(color: Colors.lightBlue),), - value: _tmpColorTemp.toDouble(), + value: _tmpColorTemp == null ? 0 : _tmpColorTemp.toDouble(), onChangeEnd: (value) => _setColorTemp(entity, value), max: entity.maxMireds, min: entity.minMireds,