awaySetColor static method

Color awaySetColor(
  1. Color? useColor,
  2. Color fromColor,
  3. int sub, {
  4. bool toUpper = true,
})

useColorfromColor保持 sub以上 的距离

Implementation

static Color awaySetColor(
  Color? useColor,
  Color fromColor,
  int sub, {
  bool toUpper = true,
}) {
  if (null == useColor) {
    return shiftColor(fromColor, sub);
  }
  int subPoint(int usePoint, int fromPoint, int limit) {
    final sub = usePoint - fromPoint;
    if (limit < 0) {
      limit = -limit;
    }
    if (sub <= limit && sub >= -limit) {
      if (toUpper) {
        return math.min((math.max(usePoint, fromPoint) + limit), 255);
      } else {
        return math.max((math.min(usePoint, fromPoint) - limit), 0);
      }
    }
    return usePoint;
  }

  return Color.fromRGBO(
    subPoint(useColor.red, fromColor.red, sub),
    subPoint(useColor.green, fromColor.green, sub),
    subPoint(useColor.blue, fromColor.blue, sub),
    1,
  );
}