我在GridView中添加了点击动画。 当我点击所有按钮时,它们都是动画的。可以修复它吗?
double _scale;
AnimationController _controller;
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void _onTapDown(TapDownDetails details) {
_controller.forward();
}
void _onTapUp(TapUpDetails details) {
_controller.reverse();
}
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 200),
lowerBound: 0.0,
upperBound: 0.1,
)..addListener(() {
setState(() {});
});
}
在构建方法中
@override
Widget build(BuildContext context) {
_scale = 1 - _controller.value;
GridView.count(
crossAxisCount: 2,
childAspectRatio: (itemWidth / itemHeight),
controller: ScrollController(keepScrollOffset: false),
shrinkWrap: true,
scrollDirection: Axis.vertical,
children: productModel.map((value) {
return Padding(
padding: EdgeInsets.all(width * .02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
onLongPressEnd: _onTapLongPressEnd,
child: Transform.scale(
scale: _scale,
child: Container(
child: Center(
child: CustomText(//text),
)),
),
)
],
),
);
}).toList(),
),
}