From f14aca5e77ab03b06639524cebc343af10138a45 Mon Sep 17 00:00:00 2001
From: Joachim Nohl <43643339+nohli@users.noreply.github.com>
Date: Fri, 24 Jun 2022 20:15:11 +0200
Subject: [PATCH] Fix alpha value dismissing (#23)
* Remove unused code
* Auto-update iOS file
* Fix alpha value dismissing, refactor color changing methods
* Update version and changelog
---
CHANGELOG.md | 4 ++++
example/ios/Runner/Info.plist | 2 ++
lib/src/color_picker.dart | 25 +++++++++++--------------
lib/src/pickers/swatches_picker.dart | 4 +---
pubspec.yaml | 2 +-
5 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 256b04b..0f6e84c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## [1.2.3]
+
+* Fix bug on color change where previously set alpha value was ignored.
+
## [1.2.2]
* Update example app.
diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist
index b77fdb4..85d4cd1 100644
--- a/example/ios/Runner/Info.plist
+++ b/example/ios/Runner/Info.plist
@@ -41,5 +41,7 @@
UIViewControllerBasedStatusBarAppearance
+ CADisableMinimumFrameDurationOnPhone
+
diff --git a/lib/src/color_picker.dart b/lib/src/color_picker.dart
index fe956f2..ab3aca4 100644
--- a/lib/src/color_picker.dart
+++ b/lib/src/color_picker.dart
@@ -1,7 +1,5 @@
import 'package:flutter/material.dart';
-import 'widgets/alpha_picker.dart';
-import 'widgets/hex_picker.dart';
import 'pickers/hsv_picker.dart';
import 'pickers/palette_hue_picker.dart';
import 'pickers/palette_saturation_picker.dart';
@@ -9,6 +7,8 @@ import 'pickers/palette_value_picker.dart';
import 'pickers/rgb_picker.dart';
import 'pickers/swatches_picker.dart';
import 'pickers/wheel_picker.dart';
+import 'widgets/alpha_picker.dart';
+import 'widgets/hex_picker.dart';
enum Picker {
swatches,
@@ -70,29 +70,26 @@ class _ColorPickerState extends State {
late int _index;
void _alphaOnChanged(int value) {
- _alpha = value;
- _color = _color.withAlpha(_alpha);
- widget.onChanged(_color);
+ _updateColor(_color.withAlpha(value));
}
void _colorOnChanged(Color value) {
- _color = value;
- _hSVColor = HSVColor.fromColor(value);
- widget.onChanged(value);
+ _updateColor(value.withAlpha(_color.alpha));
}
void _hSVColorOnChanged(HSVColor value) {
- _color = value.toColor();
- _hSVColor = value;
- widget.onChanged(value.toColor());
+ _updateColor(value.toColor().withAlpha(_color.alpha));
}
void _colorWithAlphaOnChanged(Color value) {
- _alpha = value.alpha;
- final Color color = value.withAlpha(255);
+ _updateColor(value);
+ }
+
+ void _updateColor(Color color) {
+ _alpha = color.alpha;
_color = color;
_hSVColor = HSVColor.fromColor(color);
- widget.onChanged(value);
+ widget.onChanged(color);
}
void _pickerOnChanged(_IPicker? value) {
diff --git a/lib/src/pickers/swatches_picker.dart b/lib/src/pickers/swatches_picker.dart
index 23b548c..fa11bf7 100644
--- a/lib/src/pickers/swatches_picker.dart
+++ b/lib/src/pickers/swatches_picker.dart
@@ -30,9 +30,7 @@ class _SwatchesPickerState extends State
);
}
- Widget buildListView(Color? item) {
- if (item == null) return const Divider(height: 60.0);
-
+ Widget buildListView(Color item) {
return Container(
width: 40.0,
height: 40.0,
diff --git a/pubspec.yaml b/pubspec.yaml
index 4ade008..871dec3 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: flutter_hsvcolor_picker
description: A HSV color picker inspired by chrome devtools and a material color picker for your flutter app.
-version: 1.2.2
+version: 1.2.3
homepage: https://github.com/fluttercandies/flutter_hsvcolor_picker
dependencies: