radiusFromParams function Null safety

BorderRadiusAttribute radiusFromParams(
  1. [double? p1,
  2. double? p2,
  3. double? p3,
  4. double? p4]
)

Builds radius from list using same logic as https://www.w3schools.com/cssref/css3_pr_border-radius.asp

Implementation

BorderRadiusAttribute radiusFromParams([
  double? p1,
  double? p2,
  double? p3,
  double? p4,
]) {
  final values = positionalToList(p1, p2, p3, p4);
  BorderRadiusAttribute borderRadius;

  if (values.isEmpty) {
    return BorderRadiusAttribute.none;
  }

  switch (values.length) {
    case 1:
      borderRadius = BorderRadiusAttribute.all(values[0]);
      break;
    case 2:
      final first = values[0];
      final second = values[1];
      borderRadius = BorderRadiusAttribute(
        topLeft: first,
        bottomRight: first,
        topRight: second,
        bottomLeft: second,
      );
      break;
    case 3:
      final first = values[0];
      final second = values[1];
      final third = values[2];

      borderRadius = BorderRadiusAttribute(
        topLeft: first,
        topRight: second,
        bottomLeft: second,
        bottomRight: third,
      );
      break;
    case 4:
      final first = values[0];
      final second = values[1];
      final third = values[2];
      final fourth = values[3];

      borderRadius = BorderRadiusAttribute(
        topLeft: first,
        topRight: second,
        bottomRight: third,
        bottomLeft: fourth,
      );
      break;
    default:
      borderRadius = BorderRadiusAttribute.none;
  }

  return borderRadius;
}