Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class BodyPainter extends CustomPainter {
final BuildContext context;
final BodySelectorViewModel model;
BodyPainter({
required this.context,
required this.model,
});
@override
void paint(Canvas canvas, Size size) {
var myCanvas = TouchyCanvas(context, canvas);
Paint paint = Paint()
..style = PaintingStyle.fill
..strokeWidth = 8.0;
// Scale each path to match canvas size
var xScale = size.width / 222;
var yScale = size.height / 400;
final Matrix4 matrix4 = Matrix4.identity();
matrix4.scale(xScale, yScale);
Path? bodyPath;
List<GeneralBodyPart> generalParts = model.front ? model.generalFrontBodyParts : model.generalBackBodyParts;
generalParts.forEach((muscle) {
Path path = parseSvgPath(muscle.path);
paint.color = Colors.white10;
if (model.selectedGeneralBodyPart != null && model.selectedGeneralBodyPart == muscle.name) {
paint.color = Colors.white30;
}
myCanvas.drawPath(
path.transform(matrix4.storage),
paint,
onTapDown: (details) {
model.selectGeneralBodyPart(muscle.name);
},
);
});
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment