rectanglesViewerElementFromNums static method

ViewerElement<List<Rectangle<num>>> rectanglesViewerElementFromNums(
  1. List rectangles, [
  2. Color? color,
  3. int? strokeSize
])

Converts a List if rectangles to ViewerElement< List<Rectangle<num>> >.

color Optional color to render the element. strokeSize Optional stroke size to render the element.

Implementation

static ViewerElement<List<Rectangle<num>>> rectanglesViewerElementFromNums(
    List rectangles,
    [Color? color,
    int? strokeSize]) {
  var mapped = rectangles.map((e) {
    if (e is Map) {
      return Rectangle<num>(
          parseNum(e['x'] ?? e['left'])!,
          parseNum(e['y'] ?? e['top'])!,
          parseNum(e['width'] ?? e['w'])!,
          parseNum(e['height'] ?? e['h'])!);
    } else if (e is List) {
      return Rectangle<num>(
          parseNum(e[0])!, parseNum(e[1])!, parseNum(e[2])!, parseNum(e[3])!);
    } else if (e is String) {
      var ns = parseNumsFromInlineList(e)!;
      return Rectangle<num>(parseNum(ns[0])!, parseNum(ns[1])!,
          parseNum(ns[2])!, parseNum(ns[3])!);
    } else {
      throw ArgumentError('Invalid rectangles parameter: $rectangles');
    }
  }).toList();

  return rectanglesViewerElement(mapped, color, strokeSize);
}