build method
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change.
Implementation
@override
Widget build(BuildContext context) {
SingleChildRenderObjectWidget overlayWidget;
switch (editableItem.type) {
case ItemType.TEXT:
overlayWidget = SizedBox(
width: context.width - 72,
child: Stack(
children: [
Center(
child: Text(
editableItem.value,
textAlign: TextAlign.center,
style: GoogleFonts.getFont(
fontList[editableItem.fontFamily],
).copyWith(
color: editableItem.color,
fontSize: editableItem.fontSize,
background: Paint()
..strokeWidth = TextStrokeConstants.strokeWidth
..shader = createShader(
colors: gradients[editableItem.textStyle],
width: context.width,
height: context.height,
)
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round,
),
),
),
Center(
child: GestureDetector(
onTap: onItemTap,
child: Text(
editableItem.value,
textAlign: TextAlign.center,
style: GoogleFonts.getFont(
fontList[editableItem.fontFamily],
).copyWith(
color: editableItem.color,
fontSize: editableItem.fontSize,
background: Paint()
..shader = createShader(
colors: gradients[editableItem.textStyle],
width: context.width,
height: context.height,
),
),
),
),
),
],
),
);
case ItemType.IMAGE:
overlayWidget = const Center();
case ItemType.STICKER:
// Check if the sticker is an image/GIF or emoji
final isImageSticker = editableItem.value.contains('/') ||
editableItem.value.endsWith('.png') ||
editableItem.value.endsWith('.jpg') ||
editableItem.value.endsWith('.jpeg') ||
editableItem.value.endsWith('.gif') ||
editableItem.value.startsWith('http');
overlayWidget = Center(
child: isImageSticker
? Image.file(
File(editableItem.value),
fit: BoxFit.contain,
width: editableItem.fontSize * 4,
height: editableItem.fontSize * 4,
errorBuilder: (context, error, stackTrace) {
return Icon(
Icons.broken_image,
color: Colors.white,
size: editableItem.fontSize * 2,
);
},
)
: Text(
editableItem.value,
style: TextStyle(
fontSize: editableItem.fontSize * 2,
),
),
);
}
return Positioned(
top: editableItem.position.dy * context.height,
left: editableItem.position.dx * context.width,
child: Transform.scale(
scale: editableItem.scale,
child: Transform.rotate(
angle: editableItem.rotation,
child: Listener(
onPointerDown: onPointerDown,
onPointerUp: onPointerUp,
onPointerCancel: (details) {},
onPointerMove: onPointerMove,
child: overlayWidget,
),
),
),
);
}