parseRectangleFromString function

Rectangle<num>? parseRectangleFromString(
  1. String? s
)

Parses s as a Rectangle.

Implementation

Rectangle<num>? parseRectangleFromString(String? s) {
  if (s == null) return null;
  s = s.trim();
  if (s.isEmpty) return null;

  var parts = s.split(RegExp(r'\s*,\s*'));
  if (parts.length < 4) return null;

  var nums = parts.map((e) => parseNum(e)).whereType<num>().toList();
  if (nums.length < 4) return null;

  return Rectangle<num>(nums[0], nums[1], nums[2], nums[3]);
}