Flutter 有人能解释一下如何在颤振中放大/缩小点击点(在我的例子中是双击)吗?我正在使用下面的代码

Flutter 有人能解释一下如何在颤振中放大/缩小点击点(在我的例子中是双击)吗?我正在使用下面的代码,flutter,dart,flutter-layout,flutter-dependencies,flutter-animation,Flutter,Dart,Flutter Layout,Flutter Dependencies,Flutter Animation,有人能解释一下如何放大/缩小单击的点吗?在下面的代码中,它在一个点上放大/缩小,我在transform小部件(这里是分馏Loffset.topRight)中给出了对齐值,pich to zoom也可以正常工作。有什么解决办法吗?这是我的密码 class ImageZoom extends StatefulWidget { static String routeName = "/image_zoom"; @override _ImageZoomState creat

有人能解释一下如何放大/缩小单击的点吗?在下面的代码中,它在一个点上放大/缩小,我在transform小部件(这里是分馏Loffset.topRight)中给出了对齐值,pich to zoom也可以正常工作。有什么解决办法吗?这是我的密码

class ImageZoom extends StatefulWidget {
  static String routeName = "/image_zoom";
  @override
  _ImageZoomState createState() => _ImageZoomState();
}

class _ImageZoomState extends State<ImageZoom> {
  var images = [
    "https://images.pexels.com/photos/7291782/pexels-photo-7291782.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
    "https://images.pexels.com/photos/4041366/pexels-photo-4041366.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
    "https://images.pexels.com/photos/6455888/pexels-photo-6455888.png?auto=compress&cs=tinysrgb&dpr=1&w=500",
    "https://images.pexels.com/photos/2543240/pexels-photo-2543240.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
  ];
  //pageview
  int currentIndex = 0;
  PageController _controller = PageController();

  double _scale = 1.0;
  double _previousScale = 1.0;

  void moveToPage(int index) {
    if (_controller.hasClients) {
      _controller.animateToPage(
        0,
        duration: const Duration(milliseconds: 400),
        curve: Curves.easeInOut,
      );
    }
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        backgroundColor: Colors.white,
        body: SizedBox(
          height: double.infinity,
          width: double.infinity,
          child: Column(
            children: [
              Flexible(
                flex: 1,
                child: Container(
                  child: PageView.builder(
                      pageSnapping: true,
                      reverse: false,
                      controller: _controller,
                      onPageChanged: (int page) {
                        setState(() {
                          currentIndex = page % images.length;
                          _scale = 1.0;
                        });
                      },
                      itemBuilder: (_, index) {
                        return GestureDetector(
                          onDoubleTap: () {
                            setState(() {
                              _scale = 3.0;
                            });
                          },
                          onTap: () {
                            setState(() {
                              _scale = 1.0;
                            });
                          },
                          onScaleStart: (scaleDetails) {
                            _previousScale = _scale;
                            setState(() {});
                          },
                          onScaleUpdate: (scaleDetails) {
                            _scale = _previousScale * scaleDetails.scale;
                            setState(() {});
                          },
                          onScaleEnd: (scaleDetails) {
                            _previousScale = 1.0;
                            setState(() {});
                          },
                          child: Transform(
                            alignment: FractionalOffset.topRight,
                            transform: Matrix4.diagonal3(
                                Vector3(_scale, _scale, _scale)),
                            child: Image.network(
                              images[index % images.length],
                              fit: BoxFit.contain,
                            ),
                          ),
                        );
                      }),
                ),
              ),
              Container(
                height: 80,
                color: Colors.white,
                child: ListView.separated(
                  padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
                  scrollDirection: Axis.horizontal,
                  itemBuilder: (_, index) {
                    return GestureDetector(
                      onTap: () {
                        moveToPage(index);
                      },
                      child: Container(
                        decoration: BoxDecoration(
                            border: Border(
                              bottom: BorderSide(
                                  width: 5.0,
                                  color: currentIndex == index
                                      ? Colors.green
                                      : Colors.transparent),
                            )),
                        width: 50,
                        child: ExtendedImage.network(
                          images[index],
                          fit: BoxFit.fill,
                          cache: true,
                          clearMemoryCacheWhenDispose: true,
                          clearMemoryCacheIfFailed: true,
                        ),
                      ),
                    );
                  },
                  separatorBuilder: (_, index) {
                    return SizedBox(
                      width: 5,
                    );
                  },
                  itemCount: images.length,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
class ImageZoom扩展StatefulWidget{
静态字符串routeName=“/image\u zoom”;
@凌驾
_ImageZoomState createState()=>\u ImageZoomState();
}
类_ImageZoomState扩展状态{
变量图像=[
"https://images.pexels.com/photos/7291782/pexels-photo-7291782.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
"https://images.pexels.com/photos/4041366/pexels-photo-4041366.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
"https://images.pexels.com/photos/6455888/pexels-photo-6455888.png?auto=compress&cs=tinysrgb&dpr=1&w=500",
"https://images.pexels.com/photos/2543240/pexels-photo-2543240.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
];
//页面浏览
int currentIndex=0;
PageController _controller=PageController();
双刻度=1.0;
双刻度=1.0;
无效移动页(整数索引){
if(_controller.hasClients){
_controller.animateToPage(
0,
持续时间:常量持续时间(毫秒:400),
曲线:Curves.easeInOut,
);
}
}
@凌驾
无效处置(){
super.dispose();
_controller.dispose();
}
@凌驾
小部件构建(构建上下文){
返回安全区(
孩子:脚手架(
背景颜色:Colors.white,
正文:SizedBox(
高度:双无限,
宽度:double.infinity,
子:列(
儿童:[
灵活的(
弹性:1,
子:容器(
子项:PageView.builder(
页面捕捉:对,
反面:错,
控制器:_控制器,
onPageChanged:(整版){
设置状态(){
currentIndex=页面%images.length;
_比例=1.0;
});
},
itemBuilder:(\ux,索引){
返回手势检测器(
onDoubleTap:(){
设置状态(){
_比例=3.0;
});
},
onTap:(){
设置状态(){
_比例=1.0;
});
},
按比例开始:(缩放的详细信息){
_上一个刻度=_刻度;
setState((){});
},
onScaleUpdate:(缩放详细信息){
_scale=\u previousScale*scaleDetails.scale;
setState((){});
},
onScaleEnd:(缩放尾部){
_上一个等级=1.0;
setState((){});
},
孩子:变换(
对齐:分馏Loffset.topRight,
变换:矩阵4.对角线3(
向量3(_标度,_标度,_标度)),
孩子:Image.network(
图像[索引%images.length],
适合:BoxFit.contain,
),
),
);
}),
),
),
容器(
身高:80,
颜色:颜色,白色,
子项:ListView.separated(
填充:边缘组。对称(垂直:10,水平:10),
滚动方向:轴水平,
itemBuilder:(\ux,索引){
返回手势检测器(
onTap:(){
移动页面(索引);
},
子:容器(
装饰:盒子装饰(
边界:边界(
底部:边界侧(
宽度:5.0,
颜色:currentIndex==索引
?颜色:绿色
:颜色。透明),
)),
宽度:50,
子项:ExtendedImage.network(
图像[索引],
fit:BoxFit.fill,
是的,
clearMemoryCacheWhenDispose:正确,
ClearMemoryCacheFailed:正确,
),
),
);
},
separatorBuilder:(_,索引){
返回大小框(
宽度:5,
);
},
itemCount:images.length,
),
),
],
),
),
),
);
}
}

如果您希望用户用两个手指放大和缩小图像,请将图像放入InteractiveViewer小部件中

Container(
      height: 4000,
      child: InteractiveViewer(
        maxScale: 25,
        child: Image.network(widget.image),
      ),
如果您希望用户在双击时更改图像大小,请将图像放入墨水池中,并在双击时更改高度和宽度

InkWell(
    onDoubleTap: () {
     setState(() {
       zoom = !zoom
     });
        Container(
          height: zoom ? 200 : 100,
          width: zoom ? 200 : 100,
          child: Image.asset(image))
      }
确保有缩放的初始值(或在代码中调用的任何值)