sortByHue method

void sortByHue({
  1. num startingFrom = 0,
  2. bool clockwise = true,
})
inherited

Sorts the palette by each colors hue.

startingFrom sets where on the color wheel the colors will start sorting from. startingFrom must be >= 0 && <= 360 and must not be null.

If clockwise is true, the colors will be sorted in ascending order around the color wheel. If false, they will be sorted in descending order. clockwise must not be null.

Implementation

void sortByHue({
  num startingFrom = 0,
  bool clockwise = true,
}) {
  assert(startingFrom >= 0 && startingFrom <= 360);

  colors.sort((a, b) {
    var hue1 = a.hue;
    var hue2 = b.hue;

    if (clockwise) {
      if (hue1 < startingFrom) hue1 += 360;
      if (hue2 < startingFrom) hue2 += 360;

      return hue2.compareTo(hue1);
    }

    if (hue1 < startingFrom) hue1 -= 360;
    if (hue2 < startingFrom) hue2 -= 360;

    return hue1.compareTo(hue2);
  });
}