Flutter 画贝塞尔曲线

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class FixedServiceView extends StatefulWidget{
@override
_FixedServiceView createState() {
return _FixedServiceView();
}

}

class _FixedServiceView extends State<FixedServiceView>{
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final width = size.width;
final height = size.height;

return Container(
margin: new EdgeInsets.fromLTRB(0, 0, 0, 10),
height: 180,
alignment: Alignment.center,
color: Colors.transparent,
child: ClipPath(
clipper: BottomClipper(),
child: Container(
color: Colors.white,
),
),
);
}
}

// 曲线路径
class BottomClipper extends CustomClipper<Path>{

@override
Path getClip(Size size){
var path = Path();
//第1个点
path.lineTo(0, 0);
//第2个点
var controlPoint = Offset(size.width / 2, 40);
var ednPoint = Offset(size.width, 0);
path.quadraticBezierTo(
controlPoint.dx,
controlPoint.dy,
ednPoint.dx,
ednPoint.dy
);
//第3个点
path.lineTo(size.width, size.height);
//第4个点
path.lineTo(0, size.height);

return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}
原文地址:https://www.cnblogs.com/diweinan/p/13503326.html