Layer.fromMap constructor
Implementation
factory Layer.fromMap(
Map map,
List<Uint8List> stickers,
) {
Layer layer = Layer(
flipX: map['flipX'] ?? false,
flipY: map['flipY'] ?? false,
offset: Offset(map['x'] ?? 0, map['y'] ?? 0),
rotation: map['rotation'] ?? 0,
scale: map['scale'] ?? 1,
);
switch (map['type']) {
case 'text':
return TextLayerData(
flipX: layer.flipX,
flipY: layer.flipY,
offset: layer.offset,
rotation: layer.rotation,
scale: layer.scale,
text: map['text'] ?? '-',
fontStyle: map['style'],
colorMode: LayerBackgroundColorModeE.values
.firstWhere((element) => element.name == map['colorMode']),
color: Color(map['color']),
background: Color(map['background']),
colorPickerPosition: map['colorPickerPosition'] ?? 0,
align: TextAlign.values
.firstWhere((element) => element.name == map['align']),
);
case 'emoji':
return EmojiLayerData(
flipX: layer.flipX,
flipY: layer.flipY,
offset: layer.offset,
rotation: layer.rotation,
scale: layer.scale,
emoji: map['emoji'],
);
case 'painting':
return PaintingLayerData(
flipX: layer.flipX,
flipY: layer.flipY,
offset: layer.offset,
rotation: layer.rotation,
scale: layer.scale,
rawSize: Size(
map['rawSize']?['w'] ?? 0,
map['rawSize']?['h'] ?? 0,
),
item: PaintedModel.fromMap(map['item'] ?? {}),
);
case 'sticker':
int stickerPosition = map['listPosition'] ?? -1;
Widget sticker = kDebugMode
? Text(
'Sticker $stickerPosition not found',
style: const TextStyle(color: Colors.red, fontSize: 24),
)
: const SizedBox.shrink();
if (stickers.isNotEmpty && stickers.length > stickerPosition) {
sticker = Image.memory(
stickers[stickerPosition],
width: 100,
height: 100,
);
}
return StickerLayerData(
flipX: layer.flipX,
flipY: layer.flipY,
offset: layer.offset,
rotation: layer.rotation,
scale: layer.scale,
sticker: sticker,
);
default:
return layer;
}
}