Layer.fromMap constructor

Layer.fromMap(
  1. Map<String, dynamic> map,
  2. List<Uint8List> stickers
)

Factory constructor for creating a Layer instance from a map and a list of stickers.

Implementation

factory Layer.fromMap(
  Map<String, dynamic> map,
  List<Uint8List> stickers,
) {
  /// Creates a base Layer instance with default or map-provided properties.
  Layer layer = Layer(
    flipX: map['flipX'] ?? false,
    flipY: map['flipY'] ?? false,
    enableInteraction: map['enableInteraction'] ?? true,
    offset: Offset(safeParseDouble(map['x']), safeParseDouble(map['y'])),
    rotation: safeParseDouble(map['rotation']),
    scale: safeParseDouble(map['scale'], fallback: 1),
  );

  /// Determines the layer type from the map and returns the appropriate
  /// LayerData subclass.
  switch (map['type']) {
    case 'text':

      /// Returns a TextLayerData instance when type is 'text'.
      return TextLayerData.fromMap(layer, map);
    case 'emoji':

      /// Returns an EmojiLayerData instance when type is 'emoji'.
      return EmojiLayerData.fromMap(layer, map);
    case 'painting':

      /// Returns a PaintingLayerData instance when type is 'painting'.
      return PaintingLayerData.fromMap(layer, map);
    case 'sticker':

      /// Returns a StickerLayerData instance when type is 'sticker',
      /// utilizing the stickers list.
      return StickerLayerData.fromMap(layer, map, stickers);
    default:

      /// Returns the base Layer instance when type is unrecognized.
      return layer;
  }
}