Created
April 29, 2021 12:24
-
-
Save jtmuller5/e66d42eaa32d5b2d1f5e35ddbfb5fb39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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