Created
January 8, 2020 09:40
-
-
Save BoHellgren/48cd2cc63d6d1d27c3aff89c4b20da97 to your computer and use it in GitHub Desktop.
RectPainter
This file contains 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 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