Created with <3 with dartpad.dev.
Created
July 6, 2023 18:05
-
-
Save sidroniolima/1fea5ebf208ecdfe31d857e0e004119b to your computer and use it in GitHub Desktop.
malevolent-performance-0406
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:math'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
height: 150.0, | |
child: ClipPath( | |
clipper: BackgroundClipPath(), | |
child: Container( | |
decoration: const BoxDecoration( | |
color: Color(0xFFF78770), | |
), | |
), | |
), | |
); | |
} | |
} | |
class BackgroundClipPath extends CustomClipper<Path> { | |
@override | |
Path getClip(Size size) { | |
var path = Path(); | |
int height = size.height.toInt(); | |
int beginCurve = height - 100; | |
int middleCurve = height; | |
int minBeginCurve = height~/2; | |
int waves = 5; | |
int paths = waves * 2; | |
List<Offset> offsets = []; | |
Random rdn = Random(); | |
path.lineTo(0.0, size.height - 30); | |
for (int i = 0; i < paths; i++) { | |
double dx = size.width / paths * (i + 1); | |
int ratio = minBeginCurve - rdn.nextInt(minBeginCurve - beginCurve); | |
double dy = (i%2==0) ? middleCurve.toDouble() : (ratio).toDouble(); | |
print('middle: $middleCurve, max: $beginCurve, ratio: $dy'); | |
offsets.add(Offset(dx, dy)); | |
} | |
for (int i = 0; i < paths; i+=2) { | |
path.quadraticBezierTo(offsets[i].dx, offsets[i].dy, offsets[i+1].dx, offsets[i+1].dy); | |
if (i == paths - 2) { break; } | |
} | |
path.lineTo(size.width, 0.0); | |
path.close(); | |
return path; | |
} | |
@override | |
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment