Last active
February 24, 2023 19:59
-
-
Save ShaiqAhmedkhan/f246cf927f2658fb1a6f71703ebcc580 to your computer and use it in GitHub Desktop.
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'; | |
import 'package:flutter/animation.dart'; | |
import 'package:rippledemo/circle_painter.dart'; | |
import 'package:rippledemo/curve_wave.dart'; | |
class RipplesAnimation extends StatefulWidget { | |
const RipplesAnimation({Key key, this.size = 80.0, this.color = Colors.red, | |
this.onPressed, @required this.child,}) : super(key: key); | |
final double size; | |
final Color color; | |
final Widget child; | |
final VoidCallback onPressed; | |
@override | |
_RipplesAnimationState createState() => _RipplesAnimationState(); | |
} | |
class _RipplesAnimationState extends State<RipplesAnimation> with TickerProviderStateMixin { | |
AnimationController _controller; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController( | |
duration: const Duration(milliseconds: 2000), | |
vsync: this, | |
)..repeat(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
Widget _button() { | |
return Center( | |
child: ClipRRect( | |
borderRadius: BorderRadius.circular(widget.size), | |
child: DecoratedBox( | |
decoration: BoxDecoration( | |
gradient: RadialGradient( | |
colors: <Color>[ | |
widget.color, | |
Color.lerp(widget.color, Colors.black, .05) | |
], | |
), | |
), | |
child: ScaleTransition( | |
scale: Tween(begin: 0.95, end: 1.0).animate( | |
CurvedAnimation( | |
parent: _controller, | |
curve: const CurveWave(), | |
), | |
), | |
child: Icon(Icons.speaker_phone, size: 44,) | |
), | |
), | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Flutter Ripple Demo"), | |
), | |
body: Center( | |
child: CustomPaint( | |
painter: CirclePainter( | |
_controller, | |
color: widget.color, | |
), | |
child: SizedBox( | |
width: widget.size * 4.125, | |
height: widget.size * 4.125, | |
child: _button(), | |
), | |
), | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment