Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Shadeeelection update #24

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Optimize Shadeeelection update
  • Loading branch information
Sulisong committed Jun 9, 2021
commit 823007c84465df358545c6fb2d6029e4b0e56d87
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