Skip to content

Instantly share code, notes, and snippets.

@NishantDesai1306
Created June 29, 2019 09:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NishantDesai1306/32a9d61dd7930c33d94bd560093df8b4 to your computer and use it in GitHub Desktop.
Save NishantDesai1306/32a9d61dd7930c33d94bd560093df8b4 to your computer and use it in GitHub Desktop.
code for custom painter
class MyPainter extends CustomPainter {
final Offset center;
final double radius, containerHeight;
final BuildContext context;
Color color;
double statusBarHeight, screenWidth;
MyPainter({this.context, this.containerHeight, this.center, this.radius}) {
ThemeData theme = Theme.of(context);
color = theme.primaryColor;
statusBarHeight = MediaQuery.of(context).padding.top;
screenWidth = MediaQuery.of(context).size.width;
}
@override
void paint(Canvas canvas, Size size) {
Paint circlePainter = Paint();
circlePainter.color = color;
canvas.clipRect(Rect.fromLTWH(0, 0, screenWidth, containerHeight + statusBarHeight));
canvas.drawCircle(center, radius, circlePainter);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment