i got this error with using painet in flutter:
The argument type 'ShapePainter' can't be assigned to the parameter type 'CustomPainter?'.
and my code is:
class ClipWidget extends StatelessWidget {
final Widget? childWidget;
const ClipWidget({Key? key, this.childWidget}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: [CustomPaint(
size: Size(MediaQuery.of(context).size.width,200.0),
painter: ShapePainter(),
),
],
);
}
}
class ShapePainter extends CustomPaint {
@override
void paint(Canvas canvas, Size size) {
Paint paint0 = Paint()
..color = const Color.fromARGB(255, 33, 150, 243)
..style = PaintingStyle.fill
..strokeWidth = 1;
paint0.shader = ui.Gradient.linear(Offset(size.width*0.00,size.height*0.48),Offset(size.width,size.height*0.48),[Color(0xe16ae353),Color(0xffffffff)],[0.00,1.00]);
Path path0 = Path();
path0.moveTo(size.width*0.0016500,size.height*0.0141000);
path0.quadraticBezierTo(size.width*0.0010313,size.height*0.6965250,size.width*0.0008250,size.height*0.9240000);
path0.quadraticBezierTo(size.width*0.1690625,size.height*0.7614000,size.width*0.2513500,size.height*0.4848000);
path0.quadraticBezierTo(size.width*0.4153875,size.height*0.7299000,size.width*0.5283625,size.height*0.7412000);
path0.quadraticBezierTo(size.width*0.6602125,size.height*0.7236500,size.width*0.7950000,size.height*0.2750000);
path0.quadraticBezierTo(size.width*0.8485000,size.height*0.7852000,size.width*0.9422375,size.height*0.9509000);
path0.quadraticBezierTo(size.width*0.9981250,size.height*0.9071500,size.width*0.9991500,size.height*0.7100000);
path0.lineTo(size.width,size.height*0.0150000);
canvas.drawPath(path0, paint0);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
how can i fix this error in my code?
CodePudding user response:
ShapePainter
will extend CustomPainter
instead of CustomPaint
class ShapePainter extends CustomPainter {