Skip to content

Instantly share code, notes, and snippets.

@florent37
Created July 10, 2019 07:17
Show Gist options
  • Save florent37/088431176f50c487312e1dafa85389c8 to your computer and use it in GitHub Desktop.
Save florent37/088431176f50c487312e1dafa85389c8 to your computer and use it in GitHub Desktop.
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