Created
June 3, 2020 17:13
-
-
Save joshuachinemezu/dd1d08e651105e08a6cc36a7f1c19638 to your computer and use it in GitHub Desktop.
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
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
const CURVE_HEIGHT = 250.0; | |
const AVATAR_RADIUS = CURVE_HEIGHT * 0.28; | |
const AVATAR_DIAMETER = AVATAR_RADIUS * 2; | |
class TopCurvePainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
Paint paint = new Paint() | |
..style = PaintingStyle.fill | |
..isAntiAlias = true | |
..color = Color(0xFFecebec); | |
Offset circleCenter = Offset(size.width / 2, size.height - AVATAR_RADIUS); | |
Offset topLeft = Offset(0, 0); | |
Offset bottomLeft = Offset(0, size.height * 0.25); | |
Offset topRight = Offset(size.width, 0); | |
Offset bottomRight = Offset(size.width, size.height * 0.5); | |
Offset leftCurveControlPoint = Offset(circleCenter.dx * 0.5, size.height - AVATAR_RADIUS * 1.5); | |
Offset rightCurveControlPoint = Offset(circleCenter.dx * 1.6, size.height - AVATAR_RADIUS); | |
final arcStartAngle = 30 / 20 * pi; | |
final avatarLeftPointX = circleCenter.dx + AVATAR_RADIUS * cos(arcStartAngle); | |
final avatarLeftPointY = circleCenter.dy + AVATAR_RADIUS * sin(arcStartAngle); | |
Offset avatarLeftPoint = Offset(avatarLeftPointX, avatarLeftPointY); // the left point of the arc | |
final arcEndAngle = -5 / 180 * pi; | |
final avatarRightPointX = circleCenter.dx + AVATAR_RADIUS * cos(arcEndAngle); | |
final avatarRightPointY = circleCenter.dy + AVATAR_RADIUS * sin(arcEndAngle); | |
Offset avatarRightPoint = Offset(avatarRightPointX, avatarRightPointY); // the right point of the arc | |
Path path = Path() | |
..moveTo(topLeft.dx, topLeft.dy) // this move isn't required since the start point is (0,0) | |
..lineTo(bottomLeft.dx, bottomLeft.dy) | |
..quadraticBezierTo(leftCurveControlPoint.dx, leftCurveControlPoint.dy, avatarLeftPoint.dx, avatarLeftPoint.dy) | |
..arcToPoint(avatarRightPoint, radius: Radius.circular(AVATAR_RADIUS)) | |
..quadraticBezierTo(rightCurveControlPoint.dx, rightCurveControlPoint.dy, bottomRight.dx, bottomRight.dy) | |
..lineTo(topRight.dx, topRight.dy) | |
..close(); | |
canvas.drawPath(path, paint); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) { | |
return true; | |
} | |
} | |
class CurvedShape extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.white, | |
width: double.infinity, | |
height: CURVE_HEIGHT, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment