Created
June 3, 2020 17:14
-
-
Save joshuachinemezu/776cbdba5a71ae88212752dd83369b25 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 BottomCurvePainter 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, size.height - AVATAR_RADIUS); | |
Offset topLeft = Offset(0, size.height * 0.25); | |
Offset bottomLeft = Offset(0, size.height * 100); | |
Offset topRight = Offset(size.width, size.height * 0.5); | |
Offset bottomRight = Offset(0, size.height * 0.25); | |
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 = 10 / 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 BottomCurvedShape extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return new Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.end, | |
children: <Widget>[ | |
Container( | |
width: double.infinity, | |
height: CURVE_HEIGHT, | |
child: CustomPaint( | |
painter: BottomCurvePainter(), | |
), | |
) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment