class ScaleWidget extends StatefulWidget {
const ScaleWidget({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<ScaleWidget> createState() {
return ScaleState();
}
}
class ScaleState extends State<ScaleWidget> {
double _width = 150.0; //通过修改图片宽度来达到缩放效果
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: GestureDetector(
//指定宽度,高度自适应
child: Image.asset("images/avatar.png", width: _width),
onScaleUpdate: (ScaleUpdateDetails details) {
setState(() {
//缩放倍数在0.8到10倍之间
_width=200*details.scale.clamp(.5, 10.0);
});
},
),
),
);
}
}