Dimension.css(String cssValue)

Construct a Dimension object from the valid, simple CSS string cssValue that represents a distance measurement.

This constructor is intended as a convenience method for working with simplistic CSS length measurements. Non-numeric values such as auto or inherit or invalid CSS will cause this constructor to throw a FormatError.

Source

Dimension.css(String cssValue) {
  if (cssValue == '') cssValue = '0px';
  if (cssValue.endsWith('%')) {
    _unit = '%';
  } else {
    _unit = cssValue.substring(cssValue.length - 2);
  }
  if (cssValue.contains('.')) {
    _value = double.parse(cssValue.substring(0,
        cssValue.length - _unit.length));
  } else {
    _value = int.parse(cssValue.substring(0, cssValue.length - _unit.length));
  }
}