fromJson static method

BorderRadius fromJson(
  1. Object? json
)

JSON: a number (every corner circular), [x, y] (every corner elliptical), or [topLeft, topRight, bottomRight, bottomLeft], each a number or [x, y].

Implementation

static BorderRadius fromJson(Object? json) {
  if (readDouble(json) case final double v) return BorderRadius.circular(v);
  final l = readList(json);
  if (l != null && l.length == 2) {
    final x = readDouble(l[0]), y = readDouble(l[1]);
    return x == null || y == null ? zero : BorderRadius.elliptical(x, y);
  }
  if (l == null || l.length != 4) return zero;
  (double, double) corner(Object? j) {
    if (readDouble(j) case final double v) return (v, v);
    final c = readList(j);
    if (c == null || c.length != 2) return (0, 0);
    return (readDouble(c[0]) ?? 0, readDouble(c[1]) ?? 0);
  }

  final [tl, tr, br, bl] = [for (final c in l) corner(c)];
  return BorderRadius.only(
    topLeft: tl.$1,
    topRight: tr.$1,
    bottomRight: br.$1,
    bottomLeft: bl.$1,
    topLeftY: tl.$2,
    topRightY: tr.$2,
    bottomRightY: br.$2,
    bottomLeftY: bl.$2,
  );
}