67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class WaveBackground extends StatelessWidget {
|
|
final Color color;
|
|
final double heightFactor;
|
|
|
|
const WaveBackground({
|
|
super.key,
|
|
required this.color,
|
|
this.heightFactor = 0.2,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CustomPaint(
|
|
painter: _WavePainter(color, heightFactor),
|
|
size: Size.infinite,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _WavePainter extends CustomPainter {
|
|
final Color color;
|
|
final double heightFactor;
|
|
|
|
_WavePainter(this.color, this.heightFactor);
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final paint1 = Paint()
|
|
..shader = LinearGradient(
|
|
colors: [
|
|
const Color(0xFF49BF3C),
|
|
const Color(0xFF81C784),
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
).createShader(Rect.fromLTWH(0, 0, size.width, size.height));
|
|
|
|
final path1 = Path()
|
|
..moveTo(0, size.height * heightFactor)
|
|
..quadraticBezierTo(
|
|
size.width * 0.25, size.height * 0.05, size.width * 0.5, size.height * 0.15)
|
|
..quadraticBezierTo(
|
|
size.width * 0.75, size.height * 0.25, size.width, size.height * 0.1)
|
|
..lineTo(size.width, 0)
|
|
..lineTo(0, 0)
|
|
..close();
|
|
|
|
canvas.drawPath(path1, paint1);
|
|
|
|
// Secondary wave (overlay) with same green but lighter opacity
|
|
final paint2 = Paint()..color = const Color(0xFF49BF3C).withOpacity(0.15);
|
|
final path2 = Path()
|
|
..moveTo(0, size.height * (heightFactor + 0.05))
|
|
..quadraticBezierTo(size.width * 0.4, size.height * 0.1, size.width, size.height * 0.2)
|
|
..lineTo(size.width, 0)
|
|
..lineTo(0, 0)
|
|
..close();
|
|
|
|
canvas.drawPath(path2, paint2);
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
|
}
|