diff --git a/lib/src/color_picker.dart b/lib/src/color_picker.dart index 9b0734c..dce9290 100644 --- a/lib/src/color_picker.dart +++ b/lib/src/color_picker.dart @@ -1830,8 +1830,12 @@ class _ColorPickerState extends State { ]; _findPicker(); } - // Update the active swatch to match the selected color. - _updateActiveSwatch(); + + if (_activePicker != ColorPickerType.wheel || + !ColorTools.containPrimaryColor(_activeSwatch!, _selectedColor)) { + // Update the active swatch to match the selected color. + _updateActiveSwatch(); + } }); // Call the change call back with the new color. widget.onColorChanged(_selectedColor); diff --git a/lib/src/color_tools.dart b/lib/src/color_tools.dart index 3852f7f..4f6404d 100644 --- a/lib/src/color_tools.dart +++ b/lib/src/color_tools.dart @@ -1,4 +1,5 @@ import 'dart:math'; + import 'package:flutter/material.dart'; /// Static color tool functions used internally by FlexColorPicker. @@ -199,6 +200,16 @@ class ColorTools { return false; } + /// Judgment ColorsWatch contains colors + static bool containPrimaryColor(ColorSwatch swatch, Color color) { + for (final int i in _indexPrimary) { + if (swatch[i] == color || swatch[i]?.value == color.value) { + return true; + } + } + return false; + } + /// Returns a Material primary color swatch for the color given to it. /// /// If the color is a part of a standard material primary color swatch,