Created
December 8, 2023 15:11
-
-
Save davidmigloz/c803c7ef785ef702547104424269c343 to your computer and use it in GitHub Desktop.
Generated code from pixels2flutter.dev
This file contains hidden or 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'; | |
void main() { | |
runApp(BezierCurveTesterApp()); | |
} | |
class BezierCurveTesterApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Bezier Curve Tester', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: BezierCurveTesterHomePage(), | |
); | |
} | |
} | |
class BezierCurveTesterHomePage extends StatefulWidget { | |
@override | |
_BezierCurveTesterHomePageState createState() => _BezierCurveTesterHomePageState(); | |
} | |
class _BezierCurveTesterHomePageState extends State<BezierCurveTesterHomePage> with SingleTickerProviderStateMixin { | |
late AnimationController _controller; | |
late CurvedAnimation _curvedAnimation; | |
late Animation<Offset> _animation; | |
late Curve _curve; | |
@override | |
void initState() { | |
super.initState(); | |
_curve = Cubic(0.18, 0.55, 0.81, 0.46); | |
_controller = AnimationController( | |
duration: const Duration(seconds: 10), | |
vsync: this, | |
); | |
_curvedAnimation = CurvedAnimation( | |
parent: _controller, | |
curve: _curve, | |
); | |
_animation = Tween<Offset>( | |
begin: Offset.zero, | |
end: Offset(1, 0), | |
).animate(_curvedAnimation); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
void _runAnimation() { | |
if (_controller.isAnimating) { | |
_controller.stop(); | |
} else { | |
_controller.repeat(); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Bezier Curve Tester'), | |
), | |
body: Column( | |
children: [ | |
Expanded( | |
child: Center( | |
child: CustomPaint( | |
painter: CurvePainter(curve: _curve), | |
child: Container(), | |
), | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: ElevatedButton( | |
onPressed: _runAnimation, | |
child: Text('GO!'), | |
), | |
), | |
SizedBox( | |
height: 100, | |
child: Row( | |
children: [ | |
SlideTransition( | |
position: _animation, | |
child: Container( | |
width: 50, | |
height: 50, | |
color: Colors.pink, | |
), | |
), | |
SlideTransition( | |
position: _animation, | |
child: Container( | |
width: 50, | |
height: 50, | |
color: Colors.teal, | |
), | |
), | |
], | |
), | |
), | |
// Placeholder for the library section | |
Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Text('Library Placeholder'), | |
), | |
], | |
), | |
); | |
} | |
} | |
class CurvePainter extends CustomPainter { | |
final Curve curve; | |
CurvePainter({required this.curve}); | |
@override | |
void paint(Canvas canvas, Size size) { | |
final Paint paint = Paint() | |
..color = Colors.black | |
..strokeWidth = 2 | |
..style = PaintingStyle.stroke; | |
final Path path = Path(); | |
path.moveTo(0, size.height); | |
for (double i = 0; i <= 1.0; i += 0.01) { | |
final double x = i * size.width; | |
final double y = (1 - curve.transform(i)) * size.height; | |
path.lineTo(x, y); | |
} | |
canvas.drawPath(path, paint); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment