final _transformationController = TransformationController(); //用于头像缩放
TapDownDetails? _doubleTapDetails ; //用于缩放图片是获取触摸位置
双击图片如果图片未放大那么放大 否则缩小到为放大状态
- InteractiveViewer(
- maxScale: 4,
- //panEnabled: true,
- // scaleEnabled: true,
- transformationController: _transformationController,
- child: GestureDetector(
- onDoubleTapDown: (TapDownDetails details){
- _doubleTapDetails = details; //获取触摸位置
- },
- onTap: (){
- print(Matrix4.identity());
- },
- onDoubleTap:(){
- print("双击");
- print(_transformationController.value.getMaxScaleOnAxis());//输出当前缩放倍数
- if (_transformationController.value != Matrix4.identity()) {
- //如果已经放大 缩小到1倍
- _transformationController.value = Matrix4.identity();
- } else {
- //放大图片 3倍
- final position = _doubleTapDetails!.localPosition;
- // For a 3x zoom
- _transformationController.value = Matrix4.identity()
- ..translate(-position.dx * 2, -position.dy * 2)
- ..scale(3.0);//放大倍数
- }
- },
- child: Image.network(
- imLogic.userInfo.value.faceURL!, // 替换为你的图片地址
- fit: BoxFit.fitWidth,
- ),
- ),
复制代码
藏宝库28xin.com
|