cssExpression property

  1. @override
String cssExpression

Returns the expression part of a CSS declaration. Declaration is:

property:expression;

E.g., if property is color then expression could be rgba(255,255,0) the CSS declaration would be 'color:rgba(255,255,0);'.

then _cssExpression would return 'rgba(255,255,0)'. See www.w3.org/TR/CSS21/grammar.html

Implementation

@override
String get cssExpression {
  if (_argb.length == 6) {
    return '#$_argb'; // RGB only, no alpha blending.
  } else {
    num alpha = Color.hexToInt(_argb.substring(0, 2));
    var a = (alpha / 255).toStringAsPrecision(2);
    var r = Color.hexToInt(_argb.substring(2, 4));
    var g = Color.hexToInt(_argb.substring(4, 6));
    var b = Color.hexToInt(_argb.substring(6, 8));
    return 'rgba($r,$g,$b,$a)';
  }
}