photo_view icon indicating copy to clipboard operation
photo_view copied to clipboard

Zoom with mouse wheel

Open cachapa opened this issue 4 years ago • 5 comments

On desktop the mouse wheel is ignored. The expected behavior would be for the image to zoom in when using the mouse wheel to scroll up and zoom out in the other direction.

cachapa avatar Oct 26 '21 11:10 cachapa

Hi I would like to support this. On Web we definitely need mouse support please !

tedfire avatar Apr 20 '22 09:04 tedfire

Any updates on this? My flutter web app is in production and embarrassing that it can't even zoom image with mouse scroll.

Flutter's ScaleUpdateDetails should have scale property. It should be pretty easy. When scaleUpdates.pointerCount == 0 then it's a mouse scroll.

txufiknr avatar Jun 15 '22 09:06 txufiknr

A mouse scroll event doesn't fire any gesture recognizer because there is no pointer of contact. We should rather use pointer signal

renancaraujo avatar Jul 13 '22 16:07 renancaraujo

Would be great to have this feature in the library, however here is my very basic workaround using onPointerSignal from Listener:

final _viewController = PhotoViewController();

Widget _buildPhotoView() {
    return Listener(
      onPointerSignal: (event) {
        if (event is PointerScrollEvent) {
          final delta = event.scrollDelta.dy;
          final controller = _viewController;
          if (controller != null) {
            final scale = controller.scale ?? 1.0;
            final newScale = scale - delta / 1000;
            controller.scale = newScale.clamp(1.0, 10.0);
          }
        }
      },
      child: PhotoView.customChild(
        child: FlutterLogo(),
        enablePanAlways: true,
        wantKeepAlive: true,
        backgroundDecoration: const BoxDecoration(color: Colors.grey),
        controller: _viewController,
      ),
    );
  }

mxkdev avatar Apr 28 '24 09:04 mxkdev