Skip to content

Commit

Permalink
Optimize Shadeeelection update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sulisong authored and rydmike committed Jun 11, 2021
1 parent 9f3ea18 commit d770db3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/color_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,12 @@ class _ColorPickerState extends State<ColorPicker> {
];
_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);
Expand Down
11 changes: 11 additions & 0 deletions lib/src/color_tools.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:math';

import 'package:flutter/material.dart';

/// Static color tool functions used internally by FlexColorPicker.
Expand Down Expand Up @@ -199,6 +200,16 @@ class ColorTools {
return false;
}

/// Judgment ColorsWatch contains colors
static bool containPrimaryColor(ColorSwatch<Object> 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,
Expand Down

0 comments on commit d770db3

Please sign in to comment.