StickerLayerData.fromMap constructor

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

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

Implementation

factory StickerLayerData.fromMap(
  Layer layer,
  Map<String, dynamic> map,
  List<Uint8List> stickers,
) {
  /// Determines the position of the sticker in the list.
  int stickerPosition = safeParseInt(map['listPosition'], fallback: -1);

  /// Widget to display a sticker or a placeholder if not found.
  Widget sticker = kDebugMode
      ? Text(
          'Sticker $stickerPosition not found',
          style: const TextStyle(color: Colors.red, fontSize: 24),
        )
      : const SizedBox.shrink();

  /// Updates the sticker widget if the position is valid.
  if (stickers.isNotEmpty && stickers.length > stickerPosition) {
    sticker = ConstrainedBox(
      constraints: const BoxConstraints(minWidth: 1, minHeight: 1),
      child: Image.memory(
        stickers[stickerPosition],
      ),
    );
  }

  /// Constructs and returns a StickerLayerData instance with properties
  /// derived from the layer and map.
  return StickerLayerData(
    flipX: layer.flipX,
    flipY: layer.flipY,
    enableInteraction: layer.enableInteraction,
    offset: layer.offset,
    rotation: layer.rotation,
    scale: layer.scale,
    sticker: sticker,
  );
}