toMap method

Map<String, dynamic> toMap()

Implementation

Map<String, dynamic> toMap() {
  Map shape = {};
  if (this.shape is RectangleShape) {
    RectangleShape s = this.shape as RectangleShape;
    shape['type'] = 'RectangleShape';
    shape['size'] = {'width': s.width, 'height': s.height};
  }

  if (this.shape is CircleShape) {
    CircleShape s = this.shape as CircleShape;
    shape['type'] = 'CircleShape';
    shape['radius'] = s.radius;
  }

  if (this.shape is PolygonShape) {
    PolygonShape s = this.shape as PolygonShape;
    shape['type'] = 'PolygonShape';
    shape['points'] = s.relativePoints.map((e) {
      return {'x': e.x, 'y': e.y};
    }).toList();
  }

  return {
    'shape': shape,
    'align': {'x': align?.x ?? 0.0, 'y': align?.y ?? 0.0},
  };
}