Created
July 10, 2019 07:17
-
-
Save florent37/088431176f50c487312e1dafa85389c8 to your computer and use it in GitHub Desktop.
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'; | |
class TapScaleAnimated extends StatefulWidget { | |
final Widget child; | |
final Function onTap; | |
final double scale; | |
TapScaleAnimated({this.child, @required this.onTap, this.scale = 0.9}); | |
@override | |
_TapScaleAnimatedState createState() => _TapScaleAnimatedState(); | |
} | |
class _TapScaleAnimatedState extends State<TapScaleAnimated> with SingleTickerProviderStateMixin { | |
AnimationController _scaleController; | |
@override | |
void initState() { | |
super.initState(); | |
_scaleController = AnimationController( | |
vsync: this, | |
duration: Duration(milliseconds: 200), | |
lowerBound: 0, | |
upperBound: 1 - widget.scale | |
)..addListener(() { | |
setState(() {}); | |
}); | |
} | |
@override | |
void dispose() { | |
_scaleController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return GestureDetector( | |
onTapDown: (details){ | |
_scaleController.forward(); | |
}, | |
onTapUp: (details){ | |
_scaleController.reverse(); | |
widget.onTap(); | |
}, | |
child: Transform.scale( | |
scale: 1 - _scaleController.value, | |
child: widget.child, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment