/// Created by @Haoyi on 2020/12/29 /// /// /// part of 'tips.dart'; enum TipsNip { none, left, right, top, bottom } class TipsClipper extends CustomClipper { final TipsNip nip; Radius? radius; final double nipRadius; final double nipWidth; final double nipHeight; final double nipOffset; late double _nipPX; late double _nipPY; TipsClipper( {this.nip = TipsNip.top, this.nipOffset = 0, this.radius, this.nipRadius = 4, this.nipHeight = 8, this.nipWidth = 16}) { var k = nipHeight / (nipWidth * 0.5); _nipPX = nipRadius / sqrt(1 + k * k); _nipPY = _nipPX * k; print("_nipPX:$_nipPX _nipPy:$_nipPY nipHeight:$nipHeight $nipWidth"); } @override Path getClip(Size size) { final path = Path(); switch (nip) { case TipsNip.top: path.addRRect( RRect.fromLTRBR(0, nipHeight, size.width, size.height, radius ?? Radius.circular(8))); path.moveTo(nipOffset - (nipWidth / 2), nipHeight); path.lineTo(nipOffset - _nipPX, _nipPY); path.arcToPoint(Offset(nipOffset + _nipPX, _nipPY), radius: Radius.circular(nipRadius), clockwise: true); path.lineTo(nipOffset + (nipWidth / 2), nipHeight); path.close(); break; default: break; } return path; } @override bool shouldReclip(covariant CustomClipper oldClipper) { return false; } }