Dart DocumentationbotHslColor

HslColor class

Implements

Hashable

Constructors

factory HslColor(num h, num s, num l) #

factory HslColor(num h, num s, num l) {
  requireArgument(isValidNumber(h), 'h');
  h = (h % 360);

  requireArgument(isValidNumber(s), 's', 'must be a valid number');
  requireArgument(s >= 0 && s <= 1, 's', 'must be >= 0 && <= 1 but was $s');
  requireArgument(isValidNumber(l), 'l', 'must be a valid number');
  requireArgument(l >= 0 && l <= 1, 'l', 'must be >= 0 && <=1 but was $l');

  return new HslColor._internal(h, s, l);
}

const HslColor._internal(num h, num s, num l) #

const HslColor._internal(this.h, this.s, this.l);

Fields

final num h #

final num h, s, l;

final num l #

final num h, s, l;

final num s #

final num h, s, l;

Methods

bool operator ==(HslColor other) #

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

docs inherited from Object
bool operator ==(HslColor other) {
  return other != null && other.h == h && other.s == s && other.l == l;
}

int hashCode() #

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

docs inherited from Object
int hashCode() => Util.getHashCode([h,s,l]);

noSuchMethod(String name, List args) #

inherited from Object

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

external Dynamic noSuchMethod(String name, List args);

Type get runtimeType() #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

RgbColor toRgb() #

RgbColor toRgb() {
  final normH = h / 360; // normalize h to fall in [0, 1]

  num r, g, b;

  if (s == 0) {
    r = g = b = l * 255;
  } else {
    var temp1 = 0;
    var temp2 = 0;
    if (l < 0.5) {
      temp2 = l * (1 + s);
    } else {
      temp2 = l + s - (s * l);
    }
    temp1 = 2 * l - temp2;
    r = 255 * _hueToRgb(temp1, temp2, normH + (1 / 3));
    g = 255 * _hueToRgb(temp1, temp2, normH);
    b = 255 * _hueToRgb(temp1, temp2, normH - (1 / 3));
  }

  return new RgbColor(r.round().toInt(), g.round().toInt(), b.round().toInt());
}

String toString() #

Returns a string representation of this object.

docs inherited from Object
String toString() => '{HslColor: $h, $s, $l}';