from static method

Dimension? from(
  1. Object? dimension
)

Implementation

static Dimension? from(Object? dimension) {
  if (dimension == null) return null;
  if (dimension is Dimension) return dimension;
  if (dimension is Pair) {
    var a = parseInt(dimension.a);
    var b = parseInt(dimension.b);
    return a != null && b != null ? Dimension(a, b) : null;
  }

  if (dimension is String) return Dimension.parse(dimension);

  if (dimension is List) {
    if (dimension.length == 2) {
      var w = parseInt(dimension[0]);
      var h = parseInt(dimension[1]);
      return w != null && h != null ? Dimension(w, h) : null;
    } else if (dimension.length == 1) {
      var s = parseString(dimension[0]);
      return Dimension.parse(s);
    }
  }

  if (parsers.isNotEmpty) {
    for (var p in parsers) {
      var o = p(dimension);
      if (o != null) return o;
    }
  }

  return null;
}