from<V extends CSSValue> static method

CSSEntry<V>? from<V extends CSSValue>(
  1. String name,
  2. Object? value, [
  3. String? comment
])

Implementation

static CSSEntry<V>? from<V extends CSSValue>(
  String name,
  Object? value, [
  String? comment,
]) {
  if (value == null) return null;

  if (value is CSSEntry) {
    // Keep the comment of the source entry:
    return CSSEntry<V>(
      name,
      value.value as V?,
      comment: comment ?? value._comment,
    );
  } else if (value is CSSValue) {
    return CSSEntry<V>(name, value as V, comment: comment);
  } else if (value is String) {
    var cssValue = CSSValue.parseByName(value, name);
    return CSSEntry<V>(name, cssValue as V, comment: comment);
  }

  return null;
}