Что-то вроде этого должно сделать это:
class AnimatedButton extends StatefulWidget {
@override
_AnimatedButtonState createState() => _AnimatedButtonState();
}
class _AnimatedButtonState extends State<AnimatedButton>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 200),
lowerBound: 0.0,
upperBound: 0.1,
);
_animationController.addListener(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
double scale = 1 - _animationController.value;
return GestureDetector(
onTapUp: _onTapUp,
onTapDown: _onTapDown,
child: Transform.scale(
scale: scale,
child: Container(
width: 300,
height: 75,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(38.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 5.0,
spreadRadius: 0.25,
),
],
),
),
),
);
}
void _onTapDown(TapDownDetails details) {
_animationController.forward();
}
void _onTapUp(TapUpDetails details) {
_animationController.reverse();
}
}