简体   繁体   English

Flutter:如何使下面的图像小部件在 Stack 中发挥作用

[英]Flutter: How to make the below image widget functional in Stack

I try to achieve the feature: pinch to zoom in/out an image under another overlay image.我尝试实现以下功能:捏合以放大/缩小另一个叠加图像下的图像。

My approach is using photo_view to make the main photo zoomable and put the overlay image on top of the main photo by the "stack".我的方法是使用photo_view使主照片可缩放,并通过“堆栈”将叠加图像放在主照片的顶部。

import 'package:photo_view/photo_view.dart';

class Body extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Stack(
        children: <Widget>[
          Container(
            child: PhotoView(
              initialScale: PhotoViewComputedScale.covered,
              imageProvider: AssetImage("assets/mainphoto.jpg"),
              ),
            ),
          ),
          Container(
            child: Center(
              child: AssetImage("assets/overlay.png”),
            ),
          ),
        ],
      ),
    );
  }
}

The result of the above code上面代码的结果

在此处输入图像描述

But the overlay image completely disables the main photo, I cannot pinch to zoom in/out the main photo.但是叠加图像完全禁用了主照片,我无法缩放主照片。

I think it's because of Stack, I googled around it but still don't have any proper solution.我认为这是因为 Stack,我用谷歌搜索了它,但仍然没有任何合适的解决方案。

If any suggestions, I am very appreciated.如果有任何建议,我将不胜感激。

Use IgnorePointer Widget使用IgnorePointer小部件

IgnorePointer(
  child: Container(
    child: Center(
      child: Image.asset(
        "assets/overlay.png",
      ),
    ),
  ),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM