PaintedModel.fromMap constructor

PaintedModel.fromMap(
  1. Map<String, dynamic> map
)

Factory constructor for creating a PaintedModel instance from a map.

Implementation

factory PaintedModel.fromMap(Map<String, dynamic> map) {
  /// List to hold offset points for the painting.
  List<Offset> offsets = [];

  /// Iterate over the offsets in the map and add them to the list.
  for (var el in List.from(map['offsets'])) {
    offsets.add(
      Offset(
        safeParseDouble(el['x']),
        safeParseDouble(el['y']),
      ),
    );
  }

  /// Constructs and returns a PaintedModel instance with properties
  /// derived from the map.
  return PaintedModel(
    mode: PaintModeE.values
        .firstWhere((element) => element.name == map['mode']),
    offsets: offsets,
    color: Color(map['color']),
    strokeWidth: safeParseDouble(map['strokeWidth'], fallback: 1),
    fill: map['fill'] ?? false,
    opacity: safeParseDouble(map['opacity'], fallback: 1),
  );
}