import 'dart:math' as math; import 'package:flutter/material.dart'; class WavePainter extends CustomPainter { final double animationValue; final double percentage; final Color color; WavePainter({ required this.animationValue, required this.percentage, required this.color, }); @override void paint(Canvas canvas, Size size) { final double baseHeight = size.height * (1 - percentage); final Paint paint1 = Paint() ..color = color.withOpacity(0.8) ..style = PaintingStyle.fill; final Paint paint2 = Paint() ..color = color.withOpacity(0.5) ..style = PaintingStyle.fill; final path1 = Path(); final path2 = Path(); path1.moveTo(0, baseHeight); path2.moveTo(0, baseHeight); for (double i = 0.0; i <= size.width; i++) { path1.lineTo( i, baseHeight + math.sin((i / size.width * 2 * math.pi) + (animationValue * 2 * math.pi)) * 10, ); path2.lineTo( i, baseHeight + math.sin((i / size.width * 2 * math.pi) + (animationValue * 2 * math.pi) + 1.5) * 12, ); } path1.lineTo(size.width, size.height); path1.lineTo(0, size.height); path1.close(); path2.lineTo(size.width, size.height); path2.lineTo(0, size.height); path2.close(); canvas.drawPath(path2, paint2); canvas.drawPath(path1, paint1); } @override bool shouldRepaint(covariant WavePainter oldDelegate) { return oldDelegate.animationValue != animationValue || oldDelegate.percentage != percentage || oldDelegate.color != color; } }