Skip to content

Instantly share code, notes, and snippets.

@BoHellgren
Created January 8, 2020 09:40
Show Gist options
  • Save BoHellgren/48cd2cc63d6d1d27c3aff89c4b20da97 to your computer and use it in GitHub Desktop.
Save BoHellgren/48cd2cc63d6d1d27c3aff89c4b20da97 to your computer and use it in GitHub Desktop.
RectPainter
class RectPainter extends CustomPainter {
Map rect;
RectPainter(this.rect);
@override
void paint(Canvas canvas, Size size) {
if (rect != null) {
final paint = Paint();
paint.color = Colors.yellow;
paint.style = PaintingStyle.stroke;
paint.strokeWidth = 2.0;
double x, y, w, h;
x = rect["x"] * size.width;
y = rect["y"] * size.height;
w = rect["w"] * size.width;
h = rect["h"] * size.height;
Rect rect1 = Offset(x, y) & Size(w, h);
canvas.drawRect(rect1, paint);
}
}
@override
bool shouldRepaint(RectPainter oldDelegate) => oldDelegate.rect != rect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment