简体   繁体   English

如何在 flutter 交互式查看器中仅使用鼠标左键平移?

[英]How to pan only with left mouse button in flutter interactive viewer?

I have an interactive viewer which encapsulates an image.我有一个封装图像的交互式查看器。 I want the user to only be able to pan with left mouse button and open a menu on right click.我希望用户只能用鼠标左键平移并在右键单击时打开菜单。 Currently the menu opens with right click and image also get panned with right click.当前菜单通过右键单击打开,并且图像也通过右键单击进行平移。 Is there a way to stop panning with right click in interactive viewer?有没有办法在交互式查看器中通过右键单击停止平移?

Widget build(BuildContext context) {
    return Center(
      child: InteractiveViewer(
        transformationController: _controller,
        boundaryMargin: EdgeInsets.all(10000),
        clipBehavior: Clip.none,
        minScale: 0.0001,
        maxScale: 10,
        constrained: true,
        child: Stack(
          children: [
            Align(
              alignment: AlignmentDirectional(0, 0),
              child: Image(
                image: AssetImage(widget.imagePat),
                filterQuality: FilterQuality.medium,
                isAntiAlias: true,
              ),
            ),
            Align(
              alignment: AlignmentDirectional(0.11, 0.09),
              child: SizedBox(
                width: 40,
                height: 40,
                child: TextButton(
                  style: ElevatedButton.styleFrom(
                      primary: Color.fromARGB(24, 0, 0, 0)),
                  onPressed: () => {},
                  child: Container(),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
  • Make a copy of the InteractiveViewer script to your library.将 InteractiveViewer 脚本复制到您的库中。
  • Find GestureDetector, and change 'onScale' event to 'onPan'.找到 GestureDetector,并将“onScale”事件更改为“onPan”。
  • Then make a few adjustments to those functions.然后对这些功能进行一些调整。

(smooth animation won't work after that) Also, it probably won't work on mobile. (之后平滑的 animation 将无法工作)此外,它可能无法在移动设备上使用。

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

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